Service worker is caching files but fetch event is never fired

After looking at your gist and your question, I think your issue is with scoping. From what I’ve determined with service workers(at least with static files), the service worker only has a maximum scope of the directory it is in. That is to say, it can’t load files/requests/responses that are pulled from a location at … Read more

How to alter the headers of a Request?

Creating a new request object works as long as you set all the options: // request is event.request sent by browser here var req = new Request(request.url, { method: request.method, headers: request.headers, mode: ‘same-origin’, // need to set this properly credentials: request.credentials, redirect: ‘manual’ // let browser handle redirects }); You cannot use the original … Read more

Can service workers cache POST requests?

You can’t cache POST requests using the Cache API. See https://w3c.github.io/ServiceWorker/#cache-put (point 4). There’s a related discussion in the spec repository: https://github.com/slightlyoff/ServiceWorker/issues/693 An interesting solution is the one presented in the ServiceWorker Cookbook: https://serviceworke.rs/request-deferrer.html Basically, the solution serializes requests to IndexedDB.

What can service workers do that web workers cannot?

Buksy’s answer is correct but in my opinion it does not answer the original question, namely: “What can service workers do that web workers cannot? Or vice versa?” There are fundamental differences in their lifecycle and the number of instances per origin you can have. In short: | Web Workers | Service Workers | |————–|————–|——————| … Read more

Angular 5 and Service Worker: How to exclude a particular path from ngsw-config.json

Thanks to the Pedro Arantes advice, I reached the next working config (see dataGroups and “maxAge”: “0u”): { “index”: “/index.html”, “dataGroups”: [ { “name”: “api”, “urls”: [“/api”], “cacheConfig”: { “maxSize”: 0, “maxAge”: “0u”, “strategy”: “freshness” } } ], “assetGroups”: [ { “name”: “app”, “installMode”: “prefetch”, “resources”: { “files”: [ “/favicon.ico”, “/index.html” ], “versionedFiles”: [ “/*.bundle.css”, … Read more

What causes a Failed to execute ‘fetch’ on ‘ServiceWorkerGlobalScope’: ‘only-if-cached’ can be set only with ‘same-origin’ mode error?

I believe this is a Chromium bug that has been reported here. Hopefully it will be fixed soon or some more information about the issue will be published. Paul Irish implemented a temporary work around, which is as follows: if (e.request.cache === ‘only-if-cached’ && e.request.mode !== ‘same-origin’) { return; } I ran it inside the … Read more

What is the storage limit for a service worker?

Update Jan 15 2018 The StorageManager interface of Storage API is becoming a standard for all storage related api queries. As mentioned by @miguel-lattuada, the estimate API would provide an estimate of the storage used a web app the available storage. Also, note the QuotaExceededError exception which would help us in handling error scenarios. eg … Read more

Service worker registration failed. Chrome extension

Please find below the cause for your specific issue and the cause for not getting the details of failure in the console log. Before Chrome 93, the service worker file must be in the root path where manifest.json is. This is a limitation of Service Worker specification, relaxed for extensions since Chrome 93. If, for … Read more