showing results for - "service worker js example"
Mirko
27 Oct 2020
1/*
2 Copyright 2016 Google Inc. All Rights Reserved.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
12 */
13
14// Names of the two caches used in this version of the service worker.
15// Change to v2, etc. when you update any of the local resources, which will
16// in turn trigger the install event again.
17const PRECACHE = 'precache-v1';
18const RUNTIME = 'runtime';
19
20// A list of local resources we always want to be cached.
21const PRECACHE_URLS = [
22  'index.html',
23  './', // Alias for index.html
24  'styles.css',
25  '../../styles/main.css',
26  'demo.js'
27];
28
29// The install handler takes care of precaching the resources we always need.
30self.addEventListener('install', event => {
31  event.waitUntil(
32    caches.open(PRECACHE)
33      .then(cache => cache.addAll(PRECACHE_URLS))
34      .then(self.skipWaiting())
35  );
36});
37
38// The activate handler takes care of cleaning up old caches.
39self.addEventListener('activate', event => {
40  const currentCaches = [PRECACHE, RUNTIME];
41  event.waitUntil(
42    caches.keys().then(cacheNames => {
43      return cacheNames.filter(cacheName => !currentCaches.includes(cacheName));
44    }).then(cachesToDelete => {
45      return Promise.all(cachesToDelete.map(cacheToDelete => {
46        return caches.delete(cacheToDelete);
47      }));
48    }).then(() => self.clients.claim())
49  );
50});
51
52// The fetch handler serves responses for same-origin resources from a cache.
53// If no response is found, it populates the runtime cache with the response
54// from the network before returning it to the page.
55self.addEventListener('fetch', event => {
56  // Skip cross-origin requests, like those for Google Analytics.
57  if (event.request.url.startsWith(self.location.origin)) {
58    event.respondWith(
59      caches.match(event.request).then(cachedResponse => {
60        if (cachedResponse) {
61          return cachedResponse;
62        }
63
64        return caches.open(RUNTIME).then(cache => {
65          return fetch(event.request).then(response => {
66            // Put a copy of the response in the runtime cache.
67            return cache.put(event.request, response.clone()).then(() => {
68              return response;
69            });
70          });
71        });
72      })
73    );
74  }
75});
Lina
20 Feb 2016
1if ('serviceWorker' in navigator) {  window.addEventListener('load', function() {    navigator.serviceWorker.register('/sw.js').then(function(registration) {      // Registration was successful      console.log('ServiceWorker registration successful with scope: ', registration.scope);    }, function(err) {      // registration failed :(      console.log('ServiceWorker registration failed: ', err);    });  });}
queries leading to this page
service worker tutorialuse service worker in javascriptservice worker jsservice worker in an application do whatnodejs service workerwhere to put service workergoogle search console serviceworkerlocalhost 3aservice worker jslink to service worker htmlservice worker example filewhat is a net worker servicejavascript api to check if your getting a phonecall for pwaservice worker js on httpwhat are worker and service workerwhat is a js service workerservice worker w3cuse service worker in nodejsjavascript service worker on web applicationworker servicewhat is a service worker in jshow to make a service workerwebsite service workerservice worker js pwaservice worker sample codecreate react app service worker 28from serviceworker 29simple example on service workerservice worker briefly describe the technologies used service worker script i don 27t have the service worker file in reactservice worker with phtmlservice worker c3 a9 um web workercreate service worker javascriptwhat can i do with service workerregister service worker javascriptchrome served from serviceworker 23 in url in service workerdefine service worker js javascript service workershow to write a service workerwho are considered service worker examplewhat does service worker do in javascriptwho made service workerservice workers 3a an introductionservice worker should serveice worker be started in html filejavascript workerjavascript web workerjs service workershow to register service worker in jscan i use service workeronline first service wokrehow to create a service workerreasons for service workerservice worker details jsservice worker languageservice worker in chromecreating js service workerworker service tutorialservice worker based websitewhat is servudeworker jswhats a service worker jsservice workersservice worker example websitesjs service worker examplehow does a service with worker nodes work 2fservice worker jswhen should we use service worker how service worker works with httpservice worker script examplefrom service workerwhat does service worker doservice workers appcache tutorialwhere can i install the servicewroker js fileservice worker js exampleservice worker jsservice worker code to install on androidwhat are service workerswhat does service workers mean in developmentwhat are worker serviceswhat is service worker and web workeraccess html from service workercreating a service worker javascriptservice worker nedirservice worker exampleshow to write a service worker in javascript 5chow to detecte mobile device on service wordercalling a get endpoint on the service workermake service worker in javascript service worker js tutorialhow to create a service worker in nodewhat is a service worker codegenerate service worker using javascriptservice worker usedget service worker js 23628 services worker javascriptworker service databaseserviceworker scopeo 09serviceworker jsopen service worker page in chromeservice worker web workerservice worker js track installing in service workerservice worker pass datta to new tabregistert service workerservice workercheck is service workerhow to install serviceworker javagood service worker examplewhat service worker can doconnecting serviceworker with serverjavbascript get a service workerservice worker in html5servie worker jsservice workers examplessample service worker jsservice worker code exampleservice worker js wikiservice worker min jsservices worker in javsdcriptgoogle photo service workercache manager service workerservice handler javscripyis register service worker neededjavascript register service workerhow does service worker worksadvanced service worker demoswhat is worker service node jswhat are service workersw jsjquery service workerservice workesservice workers are not enabled chromeservice worker 7ehow to use service workergood service worker code examplecan we write service worker tag in js filewhat is a worker serviceservice worker see events in uiservice workers javascripthtml service workerwhich statments are true about serviceworkerservice worker backgroun processreinstall service workerhow to host a service worker at the root of your website expressjswhat is a service worker 3fservice worker js c 23 exampleservice worker in jshow to create service workersimple background service worker javascript service workerdigital scroe service workerhow to set up a service worker on an html pageservice worker meansservice worker on server sideservice workers tutorialwhat is service worker jshow to develop service worker javascriptservice worker sw jswebsites that use service workershow to call service worker in jsservice worker reatservice workerrwhat is serviceworkers in nodejsweb worker and service workerhow to write a script to enable on and off service workerwhat is a service worker jsserver worker filewhat is service workerpossible to serve js file from service worker when onlineuse of service workerwhats a service workerservice workers in javascriptservice worker js makeservice worker thiswhat is use of service workerwhat is the service worker and web workerjs service workerway to create a service worker neatly jswhare to find service worker jsservice worker js downloadwhat a service worker can dosimple service workerservice worker chrome red crosscreate a service worker javascriptserviceworkers jsserviceworker jsjs workerhow can i use service workerwhat is a service worker javascriptjs service worker tutorialbasic service workerservice worker webjavascript example service workerwhat can i do in service workerhow to use service worker on localhostfull code for an service workerservice worker javascripthow service worker worksservice worker docsqu 27est ce que service worker in reactworker service node jscreating service workerinstall server workeronline example of web site with service workerchrome version support service workerjs code for service worker service worker starter code jsservice worker javascriptservice worker web apiservice worker what isuse of service worker javascriptwhat is service worker in jscomplete service worker exampleservice worker apiservice worker for what they are usedwhat can we do with service workerservice workers implement appcache event modelhow to use service workersservice worker see events in pagejavascript service worker exampleservice worker jsserviceworker js addservice worker 25how many service workers can have jsservice worker basicserviceworker installwhat is servive workerservice worker download filelocal service worker for javascriptjavascript get a service workerjavascript service worker libraryexample service worker jsexample service worker jsjavascript service worker templateservice worker javascript exampleservice worker scriptserviceworker filewhat is a service worker used forservice worker report cache statusjavascript service worker in js fileservice worker hspower web application service worker not working when back onlineservice workers in jsservice worker js in pwawhat is service worker and how its workweb service workerwhat is service workerscheck service worker is loading in chromewindow addeventlistener or document addeventlistener service workerwebsites using service workersserviceworker webgoogle drive service worker 27this 27 in service workerservice worker codeintroduction to service workersservice workers explainedregisterworker jsservice worker state java scriptservice worker in javascript 28from service worker 29 node jsexample of web site with service workerusing service workersinstall service workera service workerhow to install service worker in javascriptservice worker events to pagesimple service worker examplewhat are web worker and service workeri deleted service worker js fileservice worker fetch exampleservice worker weservice worker code sampleservice worker js example filewhat is a service worker in programminginistallation code for service workerwhat is service worker jsserver workersservice worker installwhat is service worker jsservice worker example usageservice worker report ststusjavascript execute code in service workerservice worker js file downloadservice worker exampleget installed service worker versiongood service worker codeservice workers chromebasics of service workersservice worker js 27 29write a service worker javascriptworker service exampleexamples of service workersjs fetch in service workerservice worker js what is itjavascript create service workerservice worker can i useuse a service workerwhat is the use of worker servicecalling an endpoint on the service workerhow to generate service worker for my appservice worker fetch in installhow to register a service worker javascriptwhat is a service workerservice worker in node jshow to make service worker jsis service worker boilerplateserviceworker js introservice workerrsserviceworker js or reportwebvital jsin app browser service workerwhat is a service worker in javascriptcan i use the service workerwhats service workerservice workers jspush technoly service workersservice worker detemine if downloadinghow to host a service worker at the root of your websiteservice worker html5 tutorialexplain service workerhow to create a service worker in javascriptwhere to find servise worker js filewhat 27s a worker serviceservice worker js documeuse service workerjavascript serviceservices workerjavascript add service workerwhere is service worker jsservice worker in onlinejs create service workerjsdom service workerdownload service worker jssw jsuse of service worker in web applicationscript service workerhow to use a service workerweb worker service workerservice worker new workergood service workerservice worker nodewhat is service workerrun serveice workernode js service workerservice worker javascript tutorialthis in service worker create service worker js fileservice worker and web workerservice worketrserviceworker javascriptservice worker for static sitehow to add service workerwhat does the service worker do 3fhwy use service worker 7e javascript service workersdoes start ul in service worker have to have slash infrontservice workers nodejsservice worker jwhen to use service workerssimple service worker codeservice worker nodejswhat are worker servicemobile service workerchrome not fetching service workersimple service worker for pwaservice worker js pwajs start service workerservice worker fileservice worker javascript w3schoolsservice worker to a web applicationhow service worker jsservice worker how tohow to install service worker in word 22this 22 in service workerhow to service workerservice worker exampleservice workers frontend or backend 3fservice worker call javascript functiona backend service workerservie workerservice worker libraryservice worker in browseropen service worker from other siteshow to write service worker jsservice worker insttall time caceservice worker enquire statusserver worker simple filewhat is service worker in javascriptbasic service worker tutorialdo i need a service worker 3fexample web site with service workerservice worker dommethods in service workerservuice workeris report webvitals and service worker js samehow to check service worker is added ornotservice worker objectservice worker example javascriptservice worker cache save passwordwhat is a service worker webget 2fservice worker jsrestore serviceworker js filewhy do i have rportwebvitals instead of service workerservice worker optionsservice worker on installservice worker node jsservice worker definitionwhy service workerwhat is service worker used forserviceworker jsservice worker in htmlsample service worker jsserviceworker js hiding codeservice worker guide create a basic service worker in jsservice worker jssevice workerservice worker css game solutionservice worker on server pwa service workerhow service worker working on server how does service worker called in html5add service worker javascriptjss service workernode js service worker exampleservice worker applicationdownload service worker js 5dservice worker for which browsersjs service worker start servicecreate service worker jsuser credentials service workerwhere is my service workerservice worker js examplewhat does a service worker dochrome extension service worker exampledoes the service worker go into source controlservice worker cache save credentials service worker templateexplain about service workercustom service worker jsservice worker htmljavascript service workerservice worker js example