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

Building Fast Angular Applications From End-to-End

Building Fast Angular Applications From End-to-End

Minko Gechev

June 07, 2019
Tweet

More Decks by Minko Gechev

Other Decks in Programming

Transcript

  1. @yourtwitter
    Building Fast Angular Applications
    From End-to-End
    Minko Gechev
    twitter.com/mgechev

    github.com/mgechev

    blog.mgechev.com

    View full-size slide

  2. @yourtwitter
    Description or Image
    @twitterhandle
    Agenda
    ● Network performance
    ● Tips & tricks
    ● Application in production

    View full-size slide

  3. @yourtwitter
    Network performance Description or Image
    @twitterhandle

    View full-size slide

  4. @yourtwitter
    Shipping less JavaScript

    View full-size slide

  5. @yourtwitter
    @mgechev
    ● Minification/dead code elimination
    ● Differential loading
    ● Code-splitting
    Shipping fewer bytes

    View full-size slide

  6. @yourtwitter
    @mgechev
    ● Minification/dead code elimination
    ● Differential loading
    ● Code-splitting
    Shipping fewer bytes

    View full-size slide

  7. @yourtwitter
    @mgechev
    Differential loading
    ● Produce ES5 bundles for newer browsers
    ● Do not send polyfills to modern browsers
    ● Smaller payload
    ● Do not downlevel modern features
    ● Faster execution
    ● Smaller payload

    View full-size slide

  8. @mgechev
    -65KB polyfills
    ~2-10% smaller bundles

    View full-size slide

  9. @mgechev
    Step 1: Load HTML Step 2: Look at script tags Step 2: Download right
    version
    Differential loading

    View full-size slide

  10. @yourtwitter
    Differential loading



    Differential loading






    View full-size slide

  11. @yourtwitter
    Differential loading



    Differential loading






    View full-size slide

  12. @yourtwitter
    @mgechev
    Differential loading
    ✅ Simple deployment infrastructure
    ✅ Proposal for a browser standard
    WHATWG

    View full-size slide

  13. @yourtwitter
    @mgechev
    ● Minification/dead code elimination
    ● Differential loading
    ● Code-splitting
    Shipping fewer bytes

    View full-size slide

  14. twitter.com/mgechev
    lazy-loading

    View full-size slide

  15. @yourtwitter
    @mgechev
    ● Component-level
    ● Route-level
    Code-splitting could be

    View full-size slide

  16. @yourtwitter
    @mgechev
    ● Component-level
    ● Route-level
    Code-splitting could be

    View full-size slide

  17. @yourtwitter
    @mgechev
    ● Component-level
    ● Route-level
    Code-splitting could be

    View full-size slide

  18. @yourtwitter
    Route-based code-splitting
    const routes: Routes = [
    {
    path: 'settings',
    loadChildren: import('./settings/settings.module')
    .then(m => m.SettingsModule);
    },

    ...
    ];

    View full-size slide

  19. twitter.com/mgechev
    Step 1: Open
    https://example.com/
    Step 2: Determine JavaScript
    which is likely to be required
    Step 3: Download the
    chunks
    Step 4: Store chunks
    in browser cache
    Pre-fetching

    View full-size slide

  20. twitter.com/mgechev

    View full-size slide

  21. @yourtwitter
    @mgechev
    ● Prefetch visible links
    ● Predictive prefetching
    ● Prefetch on mouse over
    Prefetching strategies

    View full-size slide

  22. @yourtwitter
    @mgechev
    ● Prefetch visible links
    ● Predictive prefetching
    ● Prefetch on mouse over
    Prefetching strategies

    View full-size slide

  23. @yourtwitter
    Prefetch visible links
    $ npm install ngx-quicklink

    View full-size slide

  24. @yourtwitter
    Prefetch visible links
    import { QuicklinkStrategy, QuicklinkModule } from 'ngx-quicklink';
    @NgModule({
    imports: [RouterModule.forRoot(routes, {
    preloadingStrategy: QuicklinkStrategy
    }), QuicklinkModule],
    exports: [RouterModule]
    })
    export class AppRoutingModule {}

    View full-size slide

  25. @yourtwitter
    @mgechev
    ● Prefetch visible links
    ● Predictive prefetching
    ● Prefetch on mouse over
    Prefetching strategies

    View full-size slide

  26. twitter.com/mgechev

    View full-size slide

  27. twitter.com/mgechev
    app-routing.module.ts
    pseudo code

    const routes: Routes = [
    {
    path: 'a/:id',
    loadChildren: './a.js'
    },
    {
    path: 'b',
    loadChildren: './b.js'
    }
    ];
    report
    /a/1
    /a/2 /b

    View full-size slide

  28. twitter.com/mgechev
    app-routing.module.ts
    pseudo code

    const routes: Routes = [
    {
    path: 'a/:id',
    loadChildren: './a.js'
    },
    {
    path: 'b',
    loadChildren: './b.js'
    }
    ];
    report
    /a/1
    /a/2 /b

    View full-size slide

  29. twitter.com/mgechev
    app-routing.module.ts
    pseudo code

    const routes: Routes = [
    {
    path: 'a/:id',
    loadChildren: './a.js'
    },
    {
    path: 'b',
    loadChildren: './b.js'
    }
    ];
    report
    /a/1
    /a/2 /b
    /a/:id

    View full-size slide

  30. twitter.com/mgechev
    app-routing.module.ts
    pseudo code
    const module = 'settings.module.js';
    const path = './settings';
    const routes: Routes = [
    {
    path: 'profile/:id',
    loadChildren: './profile/profile.module.js'
    },
    {
    path: 'settings',
    loadChildren: path + '/' + module,
    }
    ];

    View full-size slide

  31. twitter.com/mgechev
    app-routing.module.ts
    pseudo code
    const module = 'settings.module.js';
    const path = './settings';
    const routes: Routes = [
    {
    path: 'profile/:id',
    loadChildren: './profile/profile.module.js'
    },
    {
    path: 'settings',
    loadChildren: path + '/' + module,
    }
    ];

    View full-size slide

  32. twitter.com/mgechev
    app-routing.module.ts
    pseudo code
    const module = 'settings.module.js';
    const path = './settings';
    const routes: Routes = [
    {
    path: 'profile/:id',
    loadChildren: './profile/profile.module.js'
    },
    {
    path: 'settings',
    loadChildren: path + '/' + module,
    }
    ];

    View full-size slide

  33. @mgechev
    main.js a.js b.js c.js

    p = ( ...pairs) => {
    // Prefetch chunk
    // if connection
    // is sufficient
    };
    p(
    ['b.js', 0.3],
    ['c.js', 0.7]
    )
    p(
    ['a.js', 0.1],
    ['c.js', 0.9]
    )

    p(
    ['a.js', 1]
    )

    View full-size slide

  34. @mgechev
    A performance budget is
    a limit for pages which
    the team is not allowed to
    exceed.
    Addy Osmani

    View full-size slide

  35. @yourtwitter
    Performance Budgets
    enforces constraints to let
    you have guarantees
    v8.0.0
    https://angular.io/guide/build

    View full-size slide

  36. @yourtwitter
    One more thing
    to make your apps faster

    View full-size slide

  37. @yourtwitter
    Angular projects
    without compression
    >27%

    View full-size slide

  38. @yourtwitter
    >80%
    Angular projects
    without CDN

    View full-size slide

  39. @mgechev
    @angular/fire @azure/ng-deploy @zeit/ng-deploy

    View full-size slide

  40. @yourtwitter
    @mgechev
    Summary
    ● Reducing the bundle size
    ● Speeding up user navigations
    ● Predictive prefetching
    ● Automated deployment via CLI

    View full-size slide

  41. @mgechev
    Thank you!
    twitter.com/mgechev

    github.com/mgechev

    blog.mgechev.com

    View full-size slide