qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] Service worker is not prefetching bundles

Open jweb89 opened this issue 2 years ago • 7 comments
trafficstars

Which component is affected?

Qwik City (routing)

Describe the bug

I believe qwik should be eagerly fetching javascript via the service worker for visible things but it doesn't seem to be doing so.

Reproduction

https://www.loom.com/share/ca64ccce86054d50862e1e56f493ee3c

Steps to reproduce

Use the docs on your own browser. None of the js bundles seem to be getting prefetched the first time.

System Info

Docs currently using
"@builder.io/qwik": "BuilderIO/qwik-build#8db8f9a63f9738c1d175a6341e4519605f5f2439",
"@builder.io/qwik-city": "0.4.0",

Our site currently using:
"@builder.io/qwik": "0.19.2",
"@builder.io/qwik-city": "0.4.0",

 System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 79.94 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 3.2.3 - ~/.nvm/versions/node/v16.18.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 110.0.5481.177
    Safari: 15.6

But have tried with latest v20 as well and same results

Additional Information

No response

jweb89 avatar Feb 28 '23 19:02 jweb89

Please update to latest! 0.20.0 and 0.5.2!

manucorporat avatar Mar 01 '23 11:03 manucorporat

Please update to latest! 0.20.0 and 0.5.2!

https://www.loom.com/share/baf558e2e7cb4d33b0116ea9b08d3e8a I'm still seeing the same behavior on the latest of both

jweb89 avatar Mar 01 '23 14:03 jweb89

Having this issue as well on latest. Cloudflare workers adapter.

EamonHeffernan avatar Mar 26 '23 02:03 EamonHeffernan

I've been debugging this and wanted to point a few things out:

"Empty Cache and Hard Reload" does not appear to empty the "Cache Storage" image

I can't seem to find a good resource if that's on purpose or a bug, but regardless, in my testing, when I run the "Empty Cache and Hard Reload", the "Cache Storage" items, found in the DevTools "Application" tab, persist between reloads. It's confusing that "Empty Cache" doesn't mean "Cache Storage", but must only mean the browser's traditional network cache. Would really be interested if someone has more information on this.

So that means that if you run "Empty Cache and Hard Reload", the previously cached responses are still sitting in the "Cache Storage" ready to be used. That means when it's time to prefetch all the bundles, the service worker will say "hey, i've already got this bundle in the cache, no need to fetch it again." So it's not that it's not doing prefetching, but rather, it sees that it already has all the bundles it needs to prefetch already in the cache, so it doesn't bother.

To triple check that the service worker doesn't have any responses cached, you can safely Delete the QwikBuild storage: image

But what does seem to be off, and I think your video points out, is that fetches are happening through the main thread, on first loads. That part I haven't figured out yet and wonder if it has to do with an updated service worker (since a previous one was already installed, with different bundle names).

I'll keep debugging this, but any help or investigation would be great. Thanks

adamdbradley avatar Apr 11 '23 18:04 adamdbradley

Should also point out, to ensure you're not using a service worker on first load, go to the "Application" tab in Dev tools, and click "Service Workers" in the left menu. Then click "Unregister" for your site's installed service worker: image

And again, also make sure the "QwikBuild" cache is deleted too. With both the SW and cache storage cleared, it'll then be like a first load.

adamdbradley avatar Apr 11 '23 18:04 adamdbradley

Is there still an issue with latest version?

hamatoyogi avatar Oct 30 '23 07:10 hamatoyogi

@hamatoyogi I'm using qwik and Astro and i can observe this issue on my end too

"@builder.io/qwik": "^1.4.3",
"@qwikdev/astro": "^0.5.2",
"astro": "^4.3.1"

markkkkas avatar Feb 07 '24 20:02 markkkkas

@thejackshelton did you experience it as well?

shairez avatar Mar 05 '24 10:03 shairez

@thejackshelton did you experience it as well?

Nope, using the latest version in production and it's prefetching fine. That is, with the core service worker at least.

thejackshelton avatar Mar 05 '24 16:03 thejackshelton

Thanks @thejackshelton

So I'm closing for now Feel free to re-open if the problem still happenning

shairez avatar Mar 06 '24 15:03 shairez