sw_respondwith_serviceworker.js (555B)
1 const SERVICEWORKER_DOC = `<!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="utils.js" type="text/javascript"></script> 6 </head> 7 <body> 8 SERVICEWORKER 9 </body> 10 </html> 11 `; 12 13 const SERVICEWORKER_RESPONSE = new Response(SERVICEWORKER_DOC, { 14 headers: { "content-type": "text/html" }, 15 }); 16 17 addEventListener("fetch", event => { 18 // Allow utils.js which we explicitly include to be loaded by resetting 19 // interception. 20 if (event.request.url.endsWith("/utils.js")) { 21 return; 22 } 23 event.respondWith(SERVICEWORKER_RESPONSE.clone()); 24 });