October 2017
Intermediate to advanced
370 pages
8h 57m
English
The iframe installer is a simple HTML page that will be loaded into an iframe by the amp-install-serviceworker component when the AMP page is loaded via the cache. It uses JavaScript to install the service worker (/ch11/amptopwa/sw-install.html):
<script type="text/javascript"> if("serviceWorker" in navigator) { navigator.serviceWorker.register('/sw.js').then(function(reg){ console.log('ServiceWorker scope: ', reg.scope); }).catch(function(err) { console.warn('ServiceWorker registration failed: ', err); }); };</script>
That's it! We use the same service worker file, but by using an iframe when needed, amp-install-serviceworker can install the service worker whether the user arrives via the cache or the ...
Read now
Unlock full access