You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by ja...@apache.org on 2026/05/16 09:39:30 UTC
(pouchdb) 17/18: fix: have serviceworker only react to GET requests
This is an automated email from the ASF dual-hosted git repository.
janl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git
commit a2c8176c4d3a5a1f22750fa667816b9c25ae3cbe
Author: Alex Feyerke <al...@neighbourhood.ie>
AuthorDate: Tue May 5 11:58:26 2026 +0200
fix: have serviceworker only react to GET requests
---
docs/serviceWorker.js.liquid | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/docs/serviceWorker.js.liquid b/docs/serviceWorker.js.liquid
index 21adfbb1a..40cad2274 100644
--- a/docs/serviceWorker.js.liquid
+++ b/docs/serviceWorker.js.liquid
@@ -78,21 +78,25 @@ self.addEventListener('activate', function (event) {
});
self.addEventListener('fetch', function (event) {
- // Ignore requests from browser extensions etc
- if ((event.request.url.indexOf('http') === 0)) {
- // Try the cache, if it's not in there try the network, then cache that response
- // if that network request fails show the offline.html page.
- event.respondWith(
- caches.open(newCacheName).then(function (cache) {
- return cache.match(event.request).then(function (response) {
- return response || fetch(event.request).then(function (response) {
- cache.put(event.request, response.clone());
- return response;
- }).catch(function () {
- return cache.match('/offline.html');
+ // Ignore POST etc, which will happen when using PouchDB
+ // in the browser console
+ if(event.request.method === "GET") {
+ // Ignore requests from browser extensions etc
+ if ((event.request.url.indexOf('http') === 0)) {
+ // Try the cache, if it's not in there try the network, then cache that response
+ // if that network request fails show the offline.html page.
+ event.respondWith(
+ caches.open(newCacheName).then(function (cache) {
+ return cache.match(event.request).then(function (response) {
+ return response || fetch(event.request).then(function (response) {
+ cache.put(event.request, response.clone());
+ return response;
+ }).catch(function () {
+ return cache.match('/offline.html');
+ });
});
- });
- })
- );
+ })
+ );
+ }
}
});