cachingprogressive-web-appssw-precache

sw-precache not updating and taking only cached data


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); 
});

Solution

  • Two things to check: