小编Wan*_*eek的帖子

缓存优先策略中的内容更改时,网站未更新

我在我要支持脱机浏览的渐进式Web应用程序中使用缓存优先策略。我注意到脱机浏览正常,但是当我更新网站上的内容时,它仍然显示旧内容。我不确定我的代码有什么问题,因为我希望它在加载脱机之前检查是否有更新内容。我有manifest.json中服务的worker.jsOfflinepage.jsmain.js

这是我使用过的service-worker.js代码:

      //service worker configuration
      'use strict';

      const
        version = '1.0.0',
        CACHE = version + '::PWA',
        offlineURL = '/offline/',
        installFilesEssential = [
         '/',
          '/manifest.json',
          '/theme/pizza/css/style.css',
           '/theme/pizza/css/font-awesome/font-awesome.css',
          '/theme/pizza/javascript/script.js',
          '/theme/pizza/javascript/offlinepage.js',
          '/theme/pizza/logo.png',
          '/theme/pizza/icon.png'
        ].concat(offlineURL),
        installFilesDesirable = [
          '/favicon.ico',
         '/theme/pizza/logo.png',
          '/theme/pizza/icon.png'
        ];

      // install static assets
      function installStaticFiles() {

        return caches.open(CACHE)
          .then(cache => {

            // cache desirable files
            cache.addAll(installFilesDesirable);

            // cache essential files
            return cache.addAll(installFilesEssential);

          });

      }
      // clear old caches
      function clearOldCaches() { …
Run Code Online (Sandbox Code Playgroud)

javascript php caching progressive-web-apps

5
推荐指数
1
解决办法
735
查看次数

标签 统计

caching ×1

javascript ×1

php ×1

progressive-web-apps ×1