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

Web Performance Optimization

Jecelyn Yeen
September 18, 2019

Web Performance Optimization

Web Performance & Optimization - Images, Fonts, JavaScript

Jecelyn Yeen

September 18, 2019
Tweet

More Decks by Jecelyn Yeen

Other Decks in Technology

Transcript

  1. @JecelynYeen Software Architect Google Developer Expert - Angular - Web

    Technologies Director - NG-MY 2019 - Women Who Code KL
  2. But it takes a lot of effort to do so.

    Building features is more important… SEO doesn’t matter...
  3. [ { "resourceSizes": [ { "resourceType": "script", "budget": 309 },

    { "resourceType": "total", "budget": 500 } ], "resourceCounts": [ { "resourceType": "third-party", "budget": 10 } ] } ] Define performance budget in budget.json
  4. SVG

  5. 78% Global User WebP Has arrived Based on data from

    caniuse Source: bit.ly/webp-support Supported Supported Supported ?
  6. .png - 119 kb .webp - 28 kb .png -

    278 kb .webp - 30 kb
  7. Serve WebP and support browsers <picture> <source srcset="teh-tarik.webp" type="image/webp"> <img

    src="teh-tarik.png"> </picture> Image container If browser supports WebP Else PNG it is
  8. Lossy Image For most images, 80-85% quality will reduce file

    size by 30-40% with minimal effect on image quality
  9. Serve different image sizes <picture> <source media="(max-width: 800px)" srcset="teh-tarik-800w.webp" type="image/webp">

    <source srcset="teh-tarik.webp" type="image/webp"> <img src="teh-tarik.png" > </picture> Small screen and if browser supports WebP https://developer.mozilla.org/en-US/docs/Learn/HTML/ Multimedia_and_embedding/Responsive_images
  10. Flash of Unstyled Text (FOUT) @font-face { font-family: Google Sans',

    sans-serif; src: url('...') format('woff'); font-display: swap; } Display unstyled text until font loaded .5s improvement in “Visual Complete” on 3G
  11. Lazy Loading Traditional SPA - big-bundle.js (60kb) Split & Lazy

    Load - route-speakers.js (20kb) - route-food.js (20kb) - route-schedule.js (20kb) - ….
  12. Lazy Loading 1-2 pages per module const routes: Routes =

    [ { path: 'speakers', loadChildren: () => import('./speakers/speakers.module') .then(m => m.SpeakersModule) }, ... ]; Latest Angular version 8 syntax
  13. imports: [ ... RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) ], Preloading

    in Angular https://angular.io/api/router/PreloadAllModules Roll your own: Network aware preloading strategy