在 PWA 中将旧网址更新为新网址

luc*_*cse 5 progressive-web-apps

我正在尝试将 PWA 应用程序的 start_url 从一个页面更改为另一个页面,但需要了解其工作原理。谁能告诉我我的 PWA 应用程序用户(旧的start_url)的用户会发生什么?是否有某种更新发生后,老用户可以获得更新start_url

例如:

具有旧 start_url 的 PWA:www.testweb.com/oldurl

具有新 start_url 的 PWA:www.testweb.com/newurl

在我更改start_url.

Pet*_*eLe 1

对于 Chrome,这取决于您使用的是桌面设备还是移动设备。在桌面上,更改start_url不会有任何影响,但在 Android 上,应该会在一两天内更新。有关清单更改如何影响已安装的 PWA 的详细信息,请参阅Chrome 如何处理网络应用清单的更新。

我的建议是不要更改start_url,而是使用服务工作线程将浏览器重定向到新页面。例如,您可以使用以下内容:

self.addEventListener('fetch', (event) => {
  // Check if URL is old start_url, if so redirect to new URL
  if (event.request.url.endsWith('/previous/start_url.html')) {
    const resp = Response.redirect('/new/start_url.html', 301);
    event.respondWith(resp);
  }
});
Run Code Online (Sandbox Code Playgroud)