Проблема с кешем прогрессивных веб-приложений laravel

avatar
James
9 августа 2021 в 06:34
123
0
1

Я работаю с PWA для своего проекта laravel. Мое приложение PWA работает нормально, мой веб-сайт работает только на https, но когда я вхожу в систему, на моем веб-сайте отображаются данные моего старого зарегистрированного пользователя, как я могу решить эту проблему?

  1. Боюсь, что мой веб-сайт также работает на основе кэш-памяти
  2. Значок PWA на локальном хосте не отображается в моем браузере, как я могу решить проблему на локальном хосте

здесь я добавил js-файл поставщика услуг

// Cache API
const staticCacheName = 'app-shell-v2.0';
const filesToCache = [
  // Files
  '.',
    //css files and js file
];

self.addEventListener('install', event => {
  console.log('Installing worker to cache static assets');
  
  self.skipWaiting();
  
  event.waitUntil(
    caches.open(staticCacheName)
    .then(cache => {
      return cache.addAll(filesToCache);
    })
  );
});

self.addEventListener('activate', event => {
  console.log('Activating new worker...');
  
  const cacheWhitelist = [staticCacheName];
  self.clients.claim();
  
  event.waitUntil(
    caches.keys().then(cacheNames => {
      return Promise.all(
        cacheNames.map(cacheName => {
          if (cacheWhitelist.indexOf(cacheName) === -1) {
            return caches.delete(cacheName);
          }
        })
      );
    })
  );
});

self.addEventListener('fetch', event => {
  // exclude directories from cache
  /*if (event.request.url.match('^.*(\/admin\/).*$','^.*(\/users\/show\/).*$')) {
        return false;
  }
  if (event.request.url.endsWith('authenticate')) {
        return false;
  }*/
  console.log('Fetch event for ', event.request.url);
  event.respondWith(
    caches.match(event.request)
    .then(response => {
      if (response) {
        console.log('Found ', event.request.url, ' in cache');
        return response;
      }
      console.log('Network request for ', event.request.url);
      return fetch(event.request)
      .then(response => {
        if (response.status === 404) {
          return caches.match('https://site_url/404.html');
        }
        return caches.open(staticCacheName)
        .then(cache => {
          cache.put(event.request.url, response.clone());
          return response;
        });
      });
    }).catch(error => {
      console.log('Error, ', error);
      return caches.match('https://site_url/offline.html');
    })
  );
});
Источник

Ответы (0)