Intead of Cache The root floder, we want to cache skeleton instead.
self.addeventlistener (' Install ', function function return
Cache.addall ([
'/ ' js/main.js ' ' css/main.css ' , ' imgs/icon.png ' , ' https://fonts.gstatic.com/s /roboto/v15/2ux7wltfw3w8tcltuvlfyq.woff ' , ' https://fonts.gstatic.com/s /roboto/v15/d-6iyplofoccackzxwxsod8e0i7kzn-epnyo3hzu7kw.woff '
Respond to requests for the root page with thepage skeleton from the cache:
Self.addeventlistener (' Fetch ',function(event) { //Use the page skeleton from the cacheLet Requesturl =NewURL (Event.request.url); if(Requesturl.origin = = =Location.origin) { if(Requesturl.pathname = = = '/')) {Event.respondwith (Caches.match ('/skeleton ') ); return; }} event.respondwith (Caches.match (event.request). Then (function(response) {returnResponse | |fetch (event.request); }) );});
[PWA] 11. Serve Skeleton Cache for Root