Problem with cache Service Worker

0

I have a perfectly functioning service worker. The problem is that it is caching the logged-on user. So every time I update the page, even logged in, it shows the header unlogged. My service worker:

importScripts("{% static 'js/cache-polyfill.js' %}");
  self.addEventListener('install', function(e) {
    e.waitUntil(
      caches.open('testv1').then(function(cache) {
        return cache.addAll([
          "/",
          "{% static 'assets/css/all.css' %}",
          "{% static 'assets/js/all.js' %}",
        ]);

      })
    );
  });
self.addEventListener('fetch', function(event) {
    event.respondWith(
      caches.match(event.request).then(function(response) {
        return response || fetch(event.request);
      })
    );
  });
    
asked by anonymous 21.12.2017 / 15:36

1 answer

0

I found the solution. I needed to change my EventListener fetch, according to my need: a home that updates frequently . ( Reference )

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.open('mysite-dynamic').then(function(cache) {
      return fetch(event.request).then(function(response) {
        cache.put(event.request, response.clone());
        return response;
      });
    })
  );
});
    
21.12.2017 / 16:12