[英]Adding activate event listener to service worker
I have a service worker I am trying to setup for my website. 我有一个服务人员,我正在尝试为我的网站设置。 It uses basic html, and css.
它使用基本的html和CSS。 I need it to cache the files for offline mode.
我需要它来缓存脱机模式的文件。 I currently am stuck at adding the activate event listener, and setting up my fetch function.
目前,我一直坚持添加Activate事件监听器,并设置我的提取功能。 How do I intergrate that, and am I missing anything greater?
我该如何整合呢,我还错过了什么吗? Thanks.
谢谢。
LINK - https://jsfiddle.net/scgdhusk/2/ 链接-https: //jsfiddle.net/scgdhusk/2/
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
);
});
Well... adding the activate event listener is very simple: 好吧...添加Activate事件监听器非常简单:
self.addEventListener('activate', event => {
// do whatever you want
});
However, since your question is so simple I take it that you haven't really read through all the recommended documentation but just started to hack something together. 但是,由于您的问题非常简单,因此我认为您并没有真正阅读所有推荐的文档,而是开始一起学习。 I really advice you to read Google's introduction to Service Workers.
我真的建议您阅读Google对服务人员的介绍。 There are many, many footguns that you can avoid if you read the material.
阅读材料可以避免很多脚步枪。
:) :)
https://developers.google.com/web/fundamentals/primers/service-workers/ https://developers.google.com/web/fundamentals/primers/service-workers/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.