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

Is it possible to make an in-app button that triggers the PWA “Add to Home Screen” install banner?

Chrome(or any PWA supporting browser) triggers the beforeinstallprompt event for Web app install banner, which you can catch and re-trigger in more appropriate time when you think user wont miss it/convinced about adding your site to home page. Starting Chrome version 68, catching beforeinstallprompt and handling the install prompt programmatically is mandatory and no banners … Read more

Best practices for detecting offline state in a service worker

navigator.onLine and the related events can be useful when you want to update your UI to indicate that you’re offline and, for instance, only show content that exists in a cache. But I’d avoid writing service worker logic that relies on checking navigator.onLine. Instead, attempt to make a fetch() unconditionally, and if it fails, provide … Read more

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

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

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