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

service workers in action
SMART_READER_LITE
LIVE PREVIEW

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 + +


slide-1
SLIDE 1

Erik Witt

Service Workers in Action

35 56

Mobile

Building an Offline-Capable Webshop in under 90 minutes

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

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

slide-5
SLIDE 5

https://bit.ly/2p7bA2X

slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8

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

+ +

slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17

slide-18
SLIDE 18
slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21
slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27

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

slide-28
SLIDE 28
slide-29
SLIDE 29

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

slide-30
SLIDE 30

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

slide-31
SLIDE 31

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

slide-32
SLIDE 32

// 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/' });

slide-33
SLIDE 33

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 }); })()); });

slide-34
SLIDE 34
slide-35
SLIDE 35
slide-36
SLIDE 36
slide-37
SLIDE 37
slide-38
SLIDE 38
slide-39
SLIDE 39
slide-40
SLIDE 40
slide-41
SLIDE 41
slide-42
SLIDE 42
slide-43
SLIDE 43
slide-44
SLIDE 44
slide-45
SLIDE 45
slide-46
SLIDE 46
slide-47
SLIDE 47

Example

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

slide-48
SLIDE 48
slide-49
SLIDE 49
slide-50
SLIDE 50
slide-51
SLIDE 51
slide-52
SLIDE 52
slide-53
SLIDE 53

HTML JS CSS

slide-54
SLIDE 54

HTML JS CSS HTML

slide-55
SLIDE 55
slide-56
SLIDE 56
slide-57
SLIDE 57
slide-58
SLIDE 58

▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

slide-59
SLIDE 59
slide-60
SLIDE 60

1 2 3 4 5 6 7 8 9 10

Percentage of Traffic First Paint in Seconds

*comparing appelrath.com Chrome UX report data from October 2018 with January 2019

*

slide-61
SLIDE 61
slide-62
SLIDE 62
slide-63
SLIDE 63
slide-64
SLIDE 64

Recommended Books

https://jakearchibald.com/ https://developers.google.com/web/progressive-web-apps/

Guides & Tutorials

https://blog.baqend.com/

Blogs

https://www.igvita.com/ https://developer.mozilla.org/en-US/docs/Web/Apps/Progressive

slide-65
SLIDE 65