Challenges of angular in production (Tasos Bekos) - GreeceJS #17

greecejs 796 views 27 slides Feb 22, 2017
Slide 1
Slide 1 of 27
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27

About This Presentation

Modern web applications have constantly growing requirements and their API and complexity grows exponentially. In this session we'll look at a practical example of how to optimize solutions, like bundling, tree shaking, ahead of time compilation​, ​lazy loading, etc. Also, we will get a glim...


Slide Content

Challenges of Angular in production Tasos Bekos Frontend Architect @ ZuluTrade

Tasos Bekos Frontend Architect ZuluTrade Angular-UI Bootstrap ng-lightning @ tbekos @ bekos

Why Angular? Dependency Injection (DI) Template syntax Universal (SSR) Google Team/AngularJS

VS

Problems we faced Learning curve Training / Recruiting Breaking changes Missing libraries / resources

ng-lightning (https://github.com/ng-lightning/ng-lightning) Angular components & directives for Salesforce's Lightning Design System . S tateless functional components Accessibility

Great for collaboration Declarative syntax Designer friendly Typescript Decorators

Application Architecture Maintainability Scalability Performance “...decisions that are hard to change” Martin Fowler

Maintainability Testability Karma Protractor Automation Build: Webpack / Gulp Deployment: Jenkins Pair programming / Code reviews

Scalability Redux ( ngrx /store) Explicit update DevTools plugin Vertical separation of concerns Modules Typescript / Templates Horizontal separation of concerns Components Services API layer (Facade to backend services) Store layer (Reducers)

Pure UI Components ( onPush ) Container UI components ( async pipe) Services Store API services (Facade) Reducer Stream of immutable state slices Action State Backend response Function calls Parameters High level action/data flow @Output @Input

Performance Startup Download time Parse and compile time Runtime Javascript / CSS calculations

Startup Performance Measure and inspect Reduce size Optimize code & delivery Lazy loading

Measure & inspect webpagetest.org Chrome Timeline Webpack Bundle Analyzer

Reduce size Do not overuse libraries You don't (may not) need Lodash Make use of native Replicate small stuff Reward good behaviour Polyfill.io Don’t overuse components Can we achieve the same result with HTML/CSS ? Typescript helpers -- importHelpers   with -- noEmitHelpers

import { Observable } from ‘ rxjs /Rx' ; import { find } from ‘ lodash ' ; import { Observable } from ‘ rxjs /Observable' ; import find from ‘ lodash-es /find' ; // Just use ES6 find!! Modular libraries

Optimize code & delivery Precompilation Ahead of Time compilation optimize- js Treeshaking Webpack 2 Closure CDN publicPath : `https://mycdn.com/`

Lazy loading Code splitting Router System.import / import() Modals, Tabs, ... preload, prefetch preloadingStrategy : PreloadAllModules GoogleChrome /preload- webpack -plugin Timing 3 rd party dependencies Wrap external libraries, take advantage of lifecycle hooks

const routes : Routes = [ ... { path : 'trader' , loadChildren : './trader/ trader.module#ZlTraderModule?chunkName =trader' }, ]; plugins = [ ... new HtmlWebpackPlugin () , new PreloadWebpackPlugin ({ rel : ‘ prefetch ’, as: ‘ script ’ include: [‘ trader’ ], }) ];

Runtime Performance enableProdMode Ahead of Time compilation ( AoT ) Change detection OnPush detach/reattach Τake advantage of Router Reduce DOM size NgZone : runOutsideAngular Pure pipes, trackBy …

Future i18n during compilation time Service workers Server side rendering Angular ^4 Closure compiler for AoT

Thank you!