Open ProDeSquare opened 11 months ago
@ProDeSquare can you try this https://github.com/GoogleChrome/workbox/issues/1415#issuecomment-382458870 ? You'll need to use any of the virtual modules calling the useRegisterSW
(fw ones) or registerSW
(vanilljs)
This is the registerSW.js
code, it already has an event listener on window load
which registers the sw.js
if('serviceWorker'in navigator){window.addEventListener('load',()=>{navigator.serviceWorker.register('/sw.js',{scope:'/'})})}
Should I delay it even further?
Edit: I've started seeing the pattern. My API requests are lazy loaded.
@ProDeSquare can you try this GoogleChrome/workbox#1415 (comment) ? You'll need to use any of the virtual modules calling the
useRegisterSW
(fw ones) orregisterSW
(vanilljs)
For testing: Now my API requests are delayed 5 seconds after the page load.
Result:
I'm using
vite-plugin-pwa
with myReact.js
,Typescript
, andSWC
app. I've noticed in the dev tools it doesn't cache my API requests until the second reload. I tried a solution from this link (from StackOverflow) but it didn't help. I implemented this with:but it still caches the API response on the second reload. I also tried
dns-prefetch
andpreconnect
(according to the official documentation) with the API host but it had no effect. Is there any workaround for that, I'm using theGenerateSW
method.