sapper-template icon indicating copy to clipboard operation
sapper-template copied to clipboard

JS files are cached in offlineTTT instead of cacheTTT by service worker

Open Seb35 opened this issue 6 years ago • 0 comments

The provided service worker uses two caches: cacheTTT for static assets and bundled resources, and offlineTTT for other cached resources (with TTT a timestamp generated by Sapper).

But static assets and bundled JS resources are present in both caches:

  • in the first one when the service worker is initially populated by the 'install' event,
  • in the second one when we browse on the website.

The second one is because this condition cached.has(url.pathname) is never met because url.pathname has an initial slash (or other base URL) and the cached set is only relative to the base URL without any initial slash.

It works better (the second cache is no more populated by static assets and bundled JS resources and the service worker continues to deliver these resources) when the base URL is removed from url.pathname: cached.has(url.pathname).substring(1) where the website is on the root base URL. But I don’t know if the service worker knows its own base URL to do it programmatically without assumption on the base URL.

Seb35 avatar Apr 07 '19 23:04 Seb35