admin管理员组文章数量:1356104
This is regarding the serviceworker API that is used in Progressive Web App. Can anyone help me to understand the difference between Service worker install event and activate event?
Following are my understanding,
- Install event is the first event that occurs after registering the service worker.
- Install event only happens once - I'm not sure about this, i can see this event runs when page gets refreshed. So I'm confused with that statement.
- After the install event - activate event triggers.
- Activate event triggers every time when page reloads.
Apart from above statement, my question is what exactly the difference between two events, they both run one after another, if so why we need two events ?
Update: Sharing the resource which might help. I'm reading this.
Thanks for all the response.
This is regarding the serviceworker API that is used in Progressive Web App. Can anyone help me to understand the difference between Service worker install event and activate event?
Following are my understanding,
- Install event is the first event that occurs after registering the service worker.
- Install event only happens once - I'm not sure about this, i can see this event runs when page gets refreshed. So I'm confused with that statement.
- After the install event - activate event triggers.
- Activate event triggers every time when page reloads.
Apart from above statement, my question is what exactly the difference between two events, they both run one after another, if so why we need two events ?
Update: Sharing the resource which might help. I'm reading this. https://developers.google./web/fundamentals/instant-and-offline/service-worker/lifecycle
Thanks for all the response.
Share Improve this question edited Sep 18, 2017 at 17:38 ajeshrkurup asked Sep 18, 2017 at 17:14 ajeshrkurupajeshrkurup 1853 silver badges14 bronze badges 1- 1 Have you read the specification? – guest271314 Commented Sep 18, 2017 at 17:22
1 Answer
Reset to default 9The install event only fires when the service worker file is found to be new - either different to an existing service worker (byte-wise pared), or the first service worker encountered for this page/site.
It is good practice to cache any static files that your application may need, this means your application won't have to download these files unless they are updated.
If there is already an active service worker, the new service worker will be installed in the background - but not made active until there are no pages still using the old service worker.
The activate event will fire every time you make connection to your service worker. This is a good place to cache any extra (possibily dynamic) files, along with cleaning up old caches and things associated with the previous version of your service worker.
本文标签: javascriptService worker Install event vs Activate eventStack Overflow
版权声明:本文标题:javascript - Service worker Install event vs Activate event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743984462a2571216.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论