sw-precache not updating and taking only cached data

∥☆過路亽.° 提交于 2019-12-11 04:29:00

问题


Iam trying to implement networkfirst strategy using sw-precache.
Now iam able to cache the data and able to serve from offline. If i change the data (i.e: changed the header from 'hello' to 'Welcome') in page not get reflecting it always taking the data from the cache its getting update only if i unregistered the service worker or clear the site data then only i can get my data

Here is my sw-precache gulp task :

gulp.task('generate-service-worker', function(callback) {
  var path = require('path');
  var swPrecache = require('sw-precache');
  var rootDir = '.';

  swPrecache.write(path.join(rootDir, 'sw.js'), {
    staticFileGlobs: [
      rootDir + '/css/**.css',
      rootDir + '/js/**/*.{js,css}',
      rootDir + '/images/**/*.{png,jpg,jpeg}',
      rootDir + '/*.{html,js}',
    ],
    runtimeCaching: [
      {
        urlPattern: 'http://localhost:8080',
        handler: 'networkFirst'
      }],
    stripPrefix: rootDir
  }, callback); 
});

回答1:


Two things to check:

  • Ensure that you're not caching your sw.js file, as this could delay updates for up to 24 hours in Chrome. (Details.)
  • You're checking for updating content on the subsequent visit to the site following your update? Because of the cache-first strategy, the initial visit to the site following the update won't show the new content (because the cache has been updated "in the background").


来源:https://stackoverflow.com/questions/48283710/sw-precache-not-updating-and-taking-only-cached-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!