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

Web Performance and Optimization

Web Performance and Optimization

A survey of web performance and Optimization topics. Presented at IEEE@UC.

Topics:
- Why Performance Matters
- Chrome Developer Tools
- Tree Shaking Optimization
- Network Optimization
- Caching Files with Service Worker

Noah Bass

March 05, 2020
Tweet

More Decks by Noah Bass

Other Decks in Technology

Transcript

  1. Today’s Topics 1. Why web performance matters (Isiah) 2. Analyzing

    speed and using devtools (Isiah) 3. Tree shaking optimizations (Kristian) 4. Network optimizations across the full stack (Noah) 5. API optimizations and caching (Omar)
  2. Web Performance is ensuring content is quick to load and

    responsive to user interaction. https://developer.mozilla.org/en-US/docs/Learn/Performance
  3. What we hope you get out of today... On the

    web, every millisecond matters.
  4. In 2010, Google made pagespeed a ranking factor for desktop

    searches, in 2018 they did the same for mobile searches
  5. Pinterest increased search engine traffic and sign-ups by 15% when

    they reduced perceived wait times by 40%. https://medium.com/pinterest-engineering/driving-user-growth-with-performan ce-improvements-cfc50dafadd7
  6. What happens if you don’t optimize? Google found 53% of

    mobile site visits were abandoned if a page took longer than 3 seconds to load. https://www.thinkwithgoogle.com/marketing-resources/data-measurement/mo bile-page-speed-new-industry-benchmarks/
  7. There have been rapid gains in reported internet access rates

    in a large number of emerging and developing nations https://www.pewresearch.org/global/2016/02/22/internet-access-growing-world wide-but-remains-higher-in-advanced-economies/
  8. https://webpack.js.org Before tree shaking...there was bundling. Bundling is taking multiple

    files with dependencies and wrapping them together into a single file.
  9. nav.js node_modules/ lodash/lodash.js api.js stuff.js utils.js app.js import “...”; import

    “...”; import “...”; import “...”; import “...”; import “...”; import “...”;
  10. nav.js node_modules/ lodash/lodash.js api.js stuff.js utils.js app.js import “...”; import

    “...”; import “...”; import “...”; import “...”; import “...”; import “...”; This can be evaluated statically.
  11. nav.js node_modules/ lodash/lodash.js api.js stuff.js utils.js app.js import “...”; import

    “...”; import “...”; import “...”; import “...”; import “...”; import “...”;
  12. nav.js node_modules/ lodash/lodash.js api.js stuff.js utils.js app.js import “...”; import

    “...”; import “...”; import “...”; import “...”; import “...”; import “...”; How do we only import what we’re actually using?
  13. import seuss; import {thing1, thing2} from seuss; seuss = 1

    MB thing1, thing2 = 100 kB 900 kB savings!
  14. nav.js node_modules/ lodash/lodash.js api.js stuff.js utils.js app.js import “...”; import

    “...”; import “...”; import “...”; import “...”; import “...”; import “...”;
  15. utils.js nav.js stuff.js app.js import { lots, of, stuff }

    from “stuff.js”; import { get } from “api.js”; import { bigSort } from “utils.js”; import { hover } from “nav.js”; import { click } from “nav.js”; import sortBy from lodash-es/sortBy; api.js _.js import sortBy from lodash-es/sortBy;
  16. WebP is an alternative image format with lossy and lossless

    compression. Ok, but what does this mean? (WebP is really lightweight and fast.)
  17. Lossy WebP images average 25–35% smaller than JPEG images of

    visually similar compression levels. —Mozilla source: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
  18. What is Browser Cache? Browser cache is a temporary storage

    location on your local machine for resources that are downloaded by your browser to display web pages. Examples of downloaded (cached) contents: • HTML documents • CSS stylesheets • JavaScript scripts • Multimedia content
  19. What is a Service Worker? A service worker is a

    script that your browser runs in the background of an web page (separate from the page), allowing features that do not require any sort of user interaction like push notifications.
  20. Service Worker Life Cycle Every service worker goes through three

    steps in its lifecycle: • Registration • Installation • Activation
  21. Register the Service Worker if (!('serviceWorker' in navigator)) { console.log('Service

    Worker not supported'); return; } navigator.serviceWorker.register('/service-worker.js') .then(function(registration) { console.log('SW registered! Scope is:', registration.scope); }); // .catch a registration error https://developers.google.com/web/ilt/pwa
  22. Installing the Service Worker self.addEventListener('install', function(event) { // Do stuff

    during install }); https://developers.google.com/web/ilt/pwa
  23. Activating the Service Worker self.addEventListener('activate', function(event) { // Do stuff

    during activate }); https://developers.google.com/web/ilt/pwa