相关疑难解决方法(0)

服务工作者强制更新新资产

我一直在阅读html5rocks服务工作者文章简介,并创建了一个基本的服务工作者来缓存页面,JS和CSS按预期工作:

var CACHE_NAME = 'my-site-cache-v1';
var urlsToCache = [
  '/'
];

// Set the callback for the install step
self.addEventListener('install', function (event) {
  // Perform install steps
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('fetch', function (event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }

        // IMPORTANT: Clone the request. A request is a stream and
        // can only be consumed once. Since …
Run Code Online (Sandbox Code Playgroud)

service-worker

36
推荐指数
3
解决办法
3万
查看次数

标签 统计

service-worker ×1