service-worker

Cache asset via freshness in Angular 6 Service Worker

点点圈 提交于 2019-12-03 06:09:16
I'm trying to integrate the Angular Service Worker into a existing project. If I understood it correctly there are two cases how data gets cached in Angular SW. It is possible to prefetch or lazyupdate the asset data and to cache specific API calls and other XHR requests. What I'm trying to achieve is to load an specific asset first via network, if the request runs into a timeout or is not accessible it will be served via the cache. Just like the freshness strategy when caching API calls. But it seems that there's no possible way to configure such a freshness loading mechanism for a JS file

Can I have multiple service workers both intercept the same fetch request?

自古美人都是妖i 提交于 2019-12-03 05:43:51
问题 I'm writing a library which I will provide for 3rd parties to run a service worker on their site. It needs to intercept all network requests but I want to allow them to build their own service worker if they like. Can I have both service workers intercept the same fetches and provide some kind of priority/ordering between them? Alternatively is there some other pattern I should be using? Thanks 回答1: No, you can not. Only one service worker per scope is allowed to be registered so the latest

What is service worker in react js

喜欢而已 提交于 2019-12-03 04:41:11
问题 When creating a react app, service worker is invoked by default. Why service worker is used? What is the reason for default invoking? 回答1: You may not need a service worker for your application. If you are creating a project with create-react-app it is invoked by default Service workers are well explained in this article. To Summarise from it A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page

How to add analytics for Push notifications

偶尔善良 提交于 2019-12-03 03:41:11
I'm working on progressive web app, and I want to implement analytics for Push notifications. How can I add analytics for push notifications so that I'll be able to track and record how many people clicked on notification and how many people close that notification without clicking on it. Matt Gaunt I've written a small chunk of code to use Google analytics for analytics and it works fairly well. Dumped notes here: https://gauntface.com/blog/2016/05/01/push-debugging-analytics The way I've done this is the post mentioned above: In the service worker I import a javascript file that does the

Update Service Worker in Facebook Browser

北城余情 提交于 2019-12-03 03:26:37
Got a problem where some of our users have a buggy Service Worker sitting in their Facebook Browsers from our sites. The problem: Facebook App users are getting our 'you are offline page' on the FB browser when they access our pages shared on FB. The bug appeared to be that an old version of Google's Workbox (3.6.1) was automatically returning the 'You Are Offline' page in the FB app using Chrome 75. Updating Workbox fixed it. The reference to Workbox was in the service worker, so when we updated our Workbox version (which fixed the issue) some users still had the old one cached. If users

Recommended precache payload size?

牧云@^-^@ 提交于 2019-12-03 03:21:53
(Publicly asking/answering on behalf of someone.) I'm using Workbox to generate a service worker that precaches resources for my progressive web app. Am I wrong to be reluctant to precache ~20mb of minified JavaScript? It's huge, obviously. 20mb seems way too much. My plan was to just precache the essential stuff, and use runtime caching for the rest. In other words, what are some general heuristics for determining what should and shouldn't be included in the precache payload? There's a lot of nuance here, and the right answer comes down to a mix of understanding your users and understanding

Activate updated service worker on refresh

▼魔方 西西 提交于 2019-12-03 02:10:40
问题 When a service worker updates, it doesn't take control of the page right way; it goes into a "waiting" state, waiting to be activated. Surprisingly, the updated service worker doesn't even take control of the tab after refreshing the page. Google explains: https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/lifecycle Even if you only have one tab open to the demo, refreshing the page isn't enough to let the new version take over. This is due to how browser

What does event.waitUntil do in service worker and why is it needed?

孤人 提交于 2019-12-03 00:58:16
MDN suggests that you do the following to create and populate service worker cache: this.addEventListener('install', function(event) { event.waitUntil( caches.open('v1').then(function(cache) { return cache.addAll([ '/sw-test/', '/sw-test/index.html', ... etc ... ]); }) ); }); I do not understand that code. The waitUntil method is documented too, and it seems the code above is the single purpose of it's existence at the moment: The ExtendableEvent.waitUntil() method extends the lifetime of the event. When called in an EventHandler associated to the install event, it delays treating the

How do I sync data with remote database in case of offline-first applications?

有些话、适合烂在心里 提交于 2019-12-03 00:29:09
I am building a "TODO" application which uses Service Workers to cache the request's responses and in case a user is offline, the cached data is displayed to the user. The Server exposes an REST-ful endpoint which has POST, PUT, DELETE and GET endpoints exposed for the resources. Considering that when the user is offline and submitting a TODO item, I save that to local IndexedDB, but I can't send this POST request for the server since there is no network connection. The same is true for the PUT, DELETE requests where a user updates or deletes an existing TODO item Questions What patterns are

Storing REST requests with service workers to sync them

主宰稳场 提交于 2019-12-03 00:04:10
I'm thinking about taking my application to offline using service workers. I'm already achieving satisfying results with caching resources, but I also have to check onfetch whether I'm connected to the internet, if not - store the request, and push it onsync. I understand, that future onsync will help with that, but I need - even temporary - solution for that. I've tried just to store the requests in an array within worker, but it's not persistent - doesn't work after computer restart (while SW works and serves offline content). What's the good direction - storing it in cache like files