Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Application Performance with Angular

Web Application Performance with Angular

Avatar for S M Asad Rahman

S M Asad Rahman

November 28, 2019

More Decks by S M Asad Rahman

Other Decks in Programming

Transcript

  1. Sites performance impacts conversions q BBC lost 10% additional users

    for every addition second of their site loads q 53% of mobile users abandoned site when it takes more than 3 sec to load q Pinterest increased 15% signup by reducing perceived wait time by 40%
  2. Performance Budget q Response to user Input within 50ms q

    Generate animation frame by 10ms (60 frames/sec) q Maximize Idle time. q Optimize initial page loading to become interactive within 5s.
  3. Improve page loading q Compress and lazy load images q

    Load images with correct dimension. q Load assets from CDN. q Minify JavaScript and CSS and load asynchronously. q Differ not critical CSS. q Avoid Invisible text while font loading. q Cache assets and static APIs using service worker.
  4. Challenges q Big bundle size affects initial page loading. q

    Complex change detection affects user response time.
  5. 01. Route Level Code Splitting q Split AppModule into multiple

    “Lazy Loaded” Feature modules q With route changes lazy load corresponding feature module. q Doesn’t need to load all codes at the time of initial rendering. q Faster initial page load and page rendering.
  6. 02. Component Code Splitting q With Ivy Renderer + Angular

    9, Component can be declared without module. q Component can be lazy loaded on demand. q Results reduced feature module / AppModule bundle size. Standalone components in Ivy - Eliran Eliassy
  7. 03. Differential Loading q From Angular 8 Differential loading made

    default in ng cli. q Generates separates bundles for ES2015 and ES5. q Reduced bundle size for modern browsers.
  8. 04. Pre-Loading Lazy Modules q With default behavior “NoPreloading” feature

    modules loaded on route change. q With custom “PreloadAllModules” strategy, all feature modules can be pre-loaded. q Reduces bundle load & execution time on page transition.
  9. 05. Pre-Loading viewport links q With QuicklinkModule, custom preload strategy

    can be set. q Preloads only view port links q Preloads when browser is idle q Preloads when user is not in a slow connection. q Reduces page transition time q Uses bandwidth effectively.
  10. 06. SSR/ Angular Universal q Do the first page rendering

    in server side. q Faster FCP & FMP, because template already rendered. q SEO and SNS benefit q Need server with additional cost.
  11. 07. “OnPush” change detection q By default angular checks all

    component data for change with every user event. q Set component “ChangeDetectionStrategy” to “ChangeDetectionStrategy.OnPush” q Use immutability to change any component data. q Component will only check object reference, not each value of the object. q Reduces component rendering time for complex object.
  12. 08. “detach” change detection q Use ChangeDetectorRef to control component

    change. q Stop component’s change detection using method detach(). q Programmatically trigger change detection using method detectChanges(). q Use method markForCheck() to trigger change detection in a “OnPush” component.
  13. 09. Control CD with NgZone q Everything in angular echo

    system runs with in NgZone call stack q Change detection gets trigger when ever last function in stack executed. q Listen to frequent data changes and it’s computation within method NgZone.runOutsideAngular(). q Trigger change detection by setting value within method NgZone.run().
  14. 10. Data loading q Use Service worker to cache meta

    data Apis q Use Service worker to cache assets. q Subscribe to one observable per component. q Use concatMap, MergeMap, SwitchMap to merge multiple observable into single
  15. QnA