register <script> if (navigator.serviceWorker) { navigator.serviceWorker.register (‘/serviceworker.js’); } </script>
Slide 54
register Get the JavaScript file ‘serviceworker.js’
<script> if (navigator.serviceWorker) { navigator.serviceWorker.register (‘/serviceworker.js’); } </script>
Slide 55
register Install the JavaScript file ‘serviceworker.js’
<script> if (navigator.serviceWorker) { navigator.serviceWorker.register (‘/serviceworker.js’); } </script>
Slide 56
install
Slide 57
install
caching
Slide 58
memory cache browser cache Cache API
caching
Slide 59
install
precaching
Slide 60
install
styles.css script.js icon.png
Slide 61
install
styles.css script.js icon.png
Slide 62
install
styles.css script.js icon.png
Slide 63
install styles.css script.js icon.png
Slide 64
install styles.css script.js icon.png
Slide 65
install styles.css script.js icon.png
Slide 66
install
script.js styles.css icon.png
Slide 67
install
Slide 68
install
precaching
Slide 69
precaching When this service worker is installing open a cache and then put a bunch of files in that cache.
Slide 70
precaching When this service worker is installing
Slide 71
precaching When this service worker is installing
addEventListener()
Slide 72
precaching When this service worker is installing
addEventListener(‘install’)
Slide 73
precaching When this service worker is installing
addEventListener(‘install’, function(event) { });
Slide 74
precaching When this service worker is installing
addEventListener(‘install’, event => { });
Slide 75
precaching open a cache
Slide 76
precaching open a cache
caches.open()
Slide 77
precaching open a cache
caches.open(‘files’)
Slide 78
precaching open a cache and then
caches.open(‘files’)
Slide 79
precaching open a cache and then
caches.open(‘files’).then()
Slide 80
precaching open a cache and then
caches.open(‘files’).then( cache => { });
Slide 81
precaching put a bunch of files in that cache.
Slide 82
precaching put a bunch of files in that cache.
cache.addAll()
Slide 83
precaching put a bunch of files in that cache.
cache.addAll([ ‘/css/styles.css’, ‘/js/script.js’, ‘/img/icon.png’ ]);
Slide 84
precaching
Slide 85
precaching When this service worker is installing
addEventListener(‘install’, event => { });
Slide 86
precaching When this service worker is installing open a cache
caches.open(‘files’)
Slide 87
precaching When this service worker is installing open a cache and then
caches.open(‘files’).then( cache => { });
Slide 88
precaching When this service worker is installing open a cache and then put a bunch of files in that cache.
cache.addAll([ ‘/css/styles.css’, ‘/js/script.js’, ‘/img/icon.png’ ]);
Slide 89
precaching When this service worker is installing open a cache and then put a bunch of files in that cache.
cache first When a file is requested try to find the file in the cache first otherwise fetch the file from the network.
Slide 98
cache first When a file is requested
Slide 99
cache first When a file is requested
addEventListener()
Slide 100
cache first When a file is requested
addEventListener(‘fetch’)
Slide 101
cache first When a file is requested
addEventListener(‘fetch’, event => { });
Slide 102
cache first When a file is requested
addEventListener(‘fetch’, event => { event.respondWith( ); });
Slide 103
cache first try to find the file in the cache first
Slide 104
cache first try to find the file in the cache first
caches.match(event.request)
Slide 105
cache first try to find the file in the cache first
caches.match(event.request) .then( response => { })
Slide 106
cache first try to find the file in the cache first
caches.match(event.request) .then( response => { return response; })
Slide 107
cache first try to find the file in the cache first otherwise fetch the file from the network.
caches.match(event.request) .then( response => { return response; })
Slide 108
cache first try to find the file in the cache first otherwise fetch the file from the network.
caches.match(event.request) .then( response => { return response || fetch(event.request); })
Slide 109
cache first When a file is requested try to find the file in the cache first otherwise fetch the file from the network.
Slide 110
cache first addEventListener(‘fetch’, event => { event.respondWith(
); });
html network first cache as you go custom offline page
Slide 142
html network cache custom offline page
Slide 143
cache as you go When a page is requested try to fetch the page from the network first and store a copy in the cache otherwise try to retrieve the page from the cache otherwise retrieve the offline page from the cache.
Slide 144
Slide 145
Slide 146
Slide 147
Slide 148
Slide 149
Slide 150
Slide 151
Slide 152
Slide 153
custom offline page offline.html
Slide 154
Slide 155
css js img html cache network network cache fallback
Slide 156
css js img html speed freshness
Slide 157
articles shopping travel games reference
Slide 158
cache on demand articles
Slide 159
cache on demand When the user presses a button put a copy of this page in the cache.
Slide 160
cache on demand page.html
Slide 161
una.im
Slide 162
una.im
Slide 163
una.im
Slide 164
sarasoueidan.com
Slide 165
sarasoueidan.com
Slide 166
archive.dconstruct.org
Slide 167
archive.dconstruct.org
Slide 168
archive.dconstruct.org
Slide 169
archive.dconstruct.org
Slide 170
web app manifest https service worker
Slide 171
web app manifest <link rel=”manifest” href=”/manifest.json”>
web app manifest https service worker progressive web app
Slide 184
“ I have a really hard time describing what a progressive web app actually is.”
—What the heck is a “Progressive Web App”? Seriously.
Slide 185
“ A progressive web app is an enhanced version of a Single Page App (SPA) with a native app feel.”
—Building Progressive Web Apps
Slide 186
“ Before You Build a PWA You Need a SPA”
—hackernoon.com
Slide 187
“ I’ve seen too many devs assume PWA is a subset of SPA. We need to improve our messaging”
—Jake Archibald
Slide 188
“ A Progressive Web App is a regular website following a progressive enhancement strategy to deliver native-like user experiences by using modern Web standards.” —What is a PWA
Slide 189
“ The name isn’t for you and worrying about it is distraction from just building things that work better for everyone. … It’s marketing, just like HTML5 had very little to do with actual HTML.” —Naming Progressive Web Apps
Slide 190
Site is served over HTTPS All app URLs load while offline Metadata provided for Add to Home screen Pages are responsive First load fast even on 3G Site works cross-browser Each page has a URL Page transitions don’t block on the network
Slide 191
Site is served over HTTPS All app URLs load while offline Metadata provided for Add to Home screen Pages are responsive First load fast even on 3G Site works cross-browser Each page has a URL Page transitions don’t block on the network
Slide 192
HTTPS offline Metadata
Slide 193
HTTPS offline Metadata
HTTPS + service worker + web app manifest =
progressive web app