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

Greased Lightning

Frontend NE
September 07, 2017

Greased Lightning

How to make your web app load really, really fast as a progressive web app

Frontend NE

September 07, 2017
Tweet

More Decks by Frontend NE

Other Decks in Technology

Transcript

  1. Greased Lightning Sam Beckham @samdbeckham How to make your web

    site load really, really fast, as a progressive web app.
  2. Service worker Lighthouse 200 when offline non-javascript content https http

    => https Fast enough on 3g Prompted to install the web app Custom Splash Screen Themed Address bar <meta viewport> tag Sized correctly for the viewport
  3. ❌ Service worker Lighthouse ❌ 200 when offline ✅ non-javascript

    content ✅ https ✅ http => https ✅ Fast enough on 3g ❌ Prompted to install the web app ❌ Custom Splash Screen ❌ Themed Address bar ✅ <meta viewport> tag ✅ Sized correctly for the viewport
  4. ❌ Service worker Lighthouse ❌ 200 when offline ❌ Prompted

    to install the web app ❌ Custom Splash Screen ❌ Themed Address bar ✅ https ✅ http => https ✅ non-javascript content ✅ Fast enough on 3g ✅ <meta viewport> tag ✅ Sized correctly for the viewport
  5. self.addEventListener('install', event => { // What do we want to

    do on install? }); Install ./serviceWorker.js
  6. self.addEventListener('install', event => { event.waitUntil( caches.open('name-of-the-cache') .then(cache => cache.addAll([ '/assets/scripts/main.js',

    '/assets/scripts/forms.js', '/assets/css/main.css', '/index.html' ])) ); }); ./serviceWorker.js Install
  7. self.addEventListener('fetch', event => { // This is where the magic

    and // the dragons live. }); ./serviceWorker.js Fetch
  8. self.addEventListener('fetch', event => { const request = event.request; event.respondWith( caches.match(request)

    .then(response => { return response || fetch(request) }) ); }); ./serviceWorker.js
  9. self.addEventListener('install', event => { event.waitUntil( caches.open('name-of-the-cache') .then(cache => cache.addAll([ '/assets/scripts/main.js',

    '/assets/scripts/forms.js', '/assets/css/main.css', '/index.html' ])) ); }); self.addEventListener('fetch', event => { const request = event.request; event.respondWith( caches.match(request) .then(response => response || fetch(request)) ); }); ./serviceWorker.js
  10. Lighthouse ❌ Prompted to install the web app ❌ Custom

    Splash Screen ❌ Themed Address bar ✅ Service worker ✅ 200 when offline ✅ https ✅ http => https ✅ non-javascript content ✅ Fast enough on 3g ✅ <meta viewport> tag ✅ Sized correctly for the viewport
  11. { "name": "Frontend NE: The Conference", "short_name": "Frontend NE", "start_url":

    "/", "scope": "/", "display": "standalone", "theme_color": "#4A4A4A", "background_color": "#4A4A4A", "icons": [{ "src": "/icon.png", "sizes": "512x512", "type": "image/png" }] } ./manifest.json
  12. Lighthouse ❌ Prompted to install the web app ✅ Service

    worker ✅ 200 when offline ✅ https ✅ http => https ✅ Custom Splash Screen ✅ Themed Address bar ✅ non-javascript content ✅ Fast enough on 3g ✅ <meta viewport> tag ✅ Sized correctly for the viewport
  13. ✅ Service worker Lighthouse ✅ 200 when offline ✅ https

    ✅ http => https ✅ Prompted to install the web app ✅ Custom Splash Screen ✅ Themed Address bar ✅ non-javascript content ✅ Fast enough on 3g ✅ <meta viewport> tag ✅ Sized correctly for the viewport