Runtime caching for custom url pattern does not work in Safari
See original GitHub issueIssue Custom cached url (image from firebase storage) does not work in Safari. While Chrome and Firefox get the image from cache and therefore also work in offline mode, Safari (desktop/mobile) keeps downloading the image every time and if offline, not find anything anymore obviously.
Library Affected: workbox-sw, workbox-build, workbox-webpack-plugin etc. (default vue quasar workbox plugin)
Browser & Platform: Safari (desktop Version 13.0.3 (15608.3.10.1.4) / mobile iOS 13.1.3)
I’m using the workbox plugin for quasar. The following is a snippet from quasar.conf
file managing the pwa and workbox options. Anyway, I don’t think my issue is related to quasar or the plugin specifically but to the compatibility between workbox and safari.
pwa: {
workboxPluginMode: 'GenerateSW',
workboxOptions: {
clientsClaim: true,
navigateFallback: '/index.html',
runtimeCaching: [
{
urlPattern: new RegExp('media&token'),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'brochures-cache',
cacheableResponse: {
statuses: [0, 200]
},
fetchOptions: {
mode: 'no-cors'
}
}
},
{
urlPattern: '/',
handler: 'NetworkFirst'
}
],
},
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to cache .mp4 files in Safari with workbox-webpack-plugin?
My workbox config is precaching . mp4 assets and uses a network first strategy for runtime caching.
Read more >'Disable Caches' no longer on the Develop menu in Safari 11.0
There used to be a 'Disable Caches' option on the Develop menu, but it's no longer present in Safari 11.0. It's very useful...
Read more >Caching - web.dev
Cache storage is a powerful tool. It makes your apps less dependent on network conditions. With good use of caches you can make...
Read more >Service worker configuration - Angular
Includes both URLs and URL patterns that are matched at runtime. These resources are not fetched directly and do not have content hashes,...
Read more >next/image - Next.js
A loader is a function returning a URL string for the image, given the following parameters: ... The ** syntax does not work...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Following the steps that you provided with the https://github.com/alexeigs/debugging repo and swapping in
RegExp('^https://firebasestorage\.googleapis\.com/.*media&token')
as theRegExp
in yourGenerateSW
config leads to something that works fine offline across all browsers, in my local testing.I took these screenshots of Safari’s DevTools (both the SW version and the main page version) while offline, and the PNG response successfully comes from the SW from the perspective of the main page:
The logging in the SW DevTools shows that the
StaleWhileRevalidate
strategy is being used to handle the request and it successfully generates a response from the cache (even though “revalidate” step via the network fails):So… I’m not actually able to reproduce any issues, and I do think that switching the
RegExp
to ensure that it matches the start of the third-party URLs is necessary.Happy that you got things sorted! (And apologies that the cross-origin routing behavior can be less than intuitive without logging enabled.)