question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime caching for custom url pattern does not work in Safari

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jeffposnickcommented, Dec 3, 2019

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 the RegExp in your GenerateSW 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:

Screen Shot 2019-12-03 at 3 40 25 PM

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):

Screen Shot 2019-12-03 at 3 40 34 PM

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.

0reactions
jeffposnickcommented, Dec 4, 2019

Happy that you got things sorted! (And apologies that the cross-origin routing behavior can be less than intuitive without logging enabled.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found