gridsome-plugin-pwa
gridsome-plugin-pwa copied to clipboard
Should `disableTemplatedURLs` always be true?
We ran into a production issue with this plugin that appears to be caused by the issue first reported in #36:
- Deployed an update introducing this plugin
- Deployed an update that introduced localizations with the
gridsome-plugin-i18n
The i18n plugin was configured with the enablePathRewrite
set to true
, so that old URLs would automatically redirect to their locale-prefixed versions (ex: /about
-> /en/about
).
As soon as the second deploy went out we received reports of users getting blank and un-styled pages. We were able to reproduce by visiting pages that had the service worker registered from 1 active. If you visited a page without the trailing slash it would break, as a cached version fo the page was being served by the service worker that referenced static assets that no longer existed.
We traced it down to the bug reported in #36 and were able to resolve it by setting disableTemplatedURLs
to true
.
My question is -- what is the use case that led to the templatedURLs
logic in https://github.com/rishabh3112/gridsome-plugin-pwa/blob/master/src/files/service-worker.js#L22-L32?
Workbox Build will automatically find all of the pages that need to be pre-cached using the glob
options, and AFAICT templatedURLs
is only needed for server-rendered URLs:
If a URL is rendered based on some server-side logic, its contents may depend on multiple files or on some other unique string value. The keys in this object are server-rendered URLs. If the values are an array of strings, they will be interpreted as glob patterns, and the contents of any files matching the patterns will be used to uniquely version the URL. If used with a single string, it will be interpreted as unique versioning information that you've generated for a given URL.
See https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.generateSW
I don't think this applies to a static site generated with a tool like Gridsome, and worst case leads to stale cache entries that can break in ways that are hard to recover from without having users clear the cache storage.
I can confirm this was also a problem for me.. I am making a gridsome shopify starter and had a similar issue (routes without a trailing /
would not load css assets due to a cache issue). After debugging the whole site (reinstalling dependencies and making sure route paths were correct), setting the disableTemplatedURLs
to true
was the fix for me.