Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

progressive web apps - PWA from PWABuilder is affecting my Login/Logout Sessions

I've been using PWABuilder to make my website a PWA.

I'm using Offline copy of pages.

A solution that expands the offline capabilities of your app. A copy of each pages is stored in the cache as your visitors view them. This allows a visitor to load any previously viewed page while they are offline.

From my understanding of this, it caches pages as they are visited and if offline, show the cache if it had been stored. Sounds great!

However, when I implement this i have the following problem:

  1. I browse /user-profile/ page and because I am not logged in, I get redirected to /login/.
  2. I login (which auto-redirects to Homepage). Browse to /profile/ again.
  3. It will redirect me again to the login page because it seems to have been cached that way. If I try browse to /profile/ one further time. It works as the cache has been updated.

The same situation happens when I log out of the account. Across the website if someone makes a change to something they need to do a further refresh to see it.

Is this intended behavior? I assumed the PWA would only "kick in" when the user is seen as offline. If I remove the PWA entirely, it works as intended.

// This is the "Offline copy of assets" service worker

const CACHE = "pwabuilder-offline";

importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');

self.addEventListener("message", (event) => {
  if (event.data && event.data.type === "SKIP_WAITING") {
    self.skipWaiting();
  }
});

workbox.routing.registerRoute(
  new RegExp('/*'),
  new workbox.strategies.StaleWhileRevalidate({
    cacheName: CACHE
  })
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...