service workers in action
play

Service Workers in Action Building an Offline-Capable Webshop in - PowerPoint PPT Presentation

Erik Witt Service Workers in Action Building an Offline-Capable Webshop in under 90 minutes 35 56 Mobile Page: https://bit.ly/2p7bA2X Repository: https://github.com/ErikWitt/code-talks19 https://bit.ly/2p7bA2X + +


  1. Erik Witt Service Workers in Action Building an Offline-Capable Webshop in under 90 minutes 35 56 Mobile

  2. • • • •

  3. Page: https://bit.ly/2p7bA2X Repository: https://github.com/ErikWitt/code-talks19

  4. https://bit.ly/2p7bA2X

  5. + + Fast Loads Offline Mode Add-to- Homescreen through Caching (Synchronization) and Push Notifations

  6. • • •

  7. • •

  8. • •

  9. • • • •

  10. • • •

  11. Supported by >90% of browsers. Requires TLS Encryption.

  12. self.addEventListener('install', (event) => { // Perform install steps }); self.addEventListener('activate', (event) => { // Perform activate steps }); self.addEventListener('fetch', (event) => { // React to fetch event });

  13. self.addEventListener('message', (event) => { // Receive message }); // Send message to browser tab self.addEventListener('push', (event) => { const client = await clients.get('id'); // Receive push notification client.postMessage(someJsonData); });

  14. // Default (and maximum) scope is location of Service Worker // Gets all requests starting with '/path/' navigator.serviceWorker.register('/path/sw.js');

  15. // Scope option can further limit which requests got to Service Worker // Gets all requests starting with '/path/subpath/' navigator.serviceWorker.register('/path/sw.js', { scope: '/path/subpath/' });

  16. self.addEventListener('fetch', (event) => { // React to fetch event • const { url } = event.request; event.respondWith((async () => { • const request = new Request(url.replace('.com', '.de')) • const response = await fetch(request); const text = await response.text(); • const newText = text.replace('Goethe', 'Schiller'); • return new Response(newText, { status: 200 }); })()); • });

  17. • • • •

  18. • • • • • •

  19. • • • •

  20. Example 1500 entries & 0.0019% false positives → 7 KB size ↓ >25% cache hits on HTML in production

  21. HTML CSS JS

  22. HTML HTML CSS JS

  23. ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

  24. * Percentage of Traffic 0 1 2 3 4 5 6 7 8 9 10 First Paint in Seconds *comparing appelrath.com Chrome UX report data from October 2018 with January 2019

  25. Recommended Books Blogs https://blog.baqend.com/ https://www.igvita.com/ https://jakearchibald.com/ Guides & Tutorials https://developers.google.com/web/progressive-web-apps/ https://developer.mozilla.org/en-US/docs/Web/Apps/Progressive

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend