Dear js gurus in my timeline, is this the correct way to exclude urls from the power of ServiceWorkers?
(...) self.addEventListener('fetch', function (event) { var request = event.request; // if is request for cms admin, do nothing. if(request.url.indexOf('/blog/wp-admin/') !== -1){ return; } // Always fetch non-GET requests from the network if (request.method !== 'GET') { event.respondWith( fetch(request) .catch(function () { return caches.match('/offline.html'); }) ); return; } (...) |
Sorry for asking, but I'm still in baby step mode for this new and exiting power-up the web has now, and I'm trying to counter-act some strange effects I'm getting when I use my site's backend: Everytime a Ajax-y thing happens, like uploading a picture or deleting posts from an overview/list, the page will display the code of the Serviceworker-JS. The desired action worked, though, and by using the "back" button of the browser, the backend is workable again.
I haven't had this effect since I included the lines above, but frankly I have no idea what side effects this may cause elsewhere.
(living example: webrocker.de/sw.js)
11 Reaktionen zu “Wrestling with the ServiceWorker”
Ich hab das bei mir so (oder so ähnlich) umgesetzt:
Prinzip: wenn die fetch-Anfrage mit einem der requests aus dem neverCache-Array matcht (mit Deiner https-BaseURL), dann bitte nix cachen, aber im Notfall die offline-Seite anzeigen).
Prinzip ist das gleiche, aber ich wollte mehrere Dateien explizit nicht cachen... kannste auch unter /serviceworker.js anschauen :)
Kommentare sind geschlossen.