QwikDev/qwik

[๐Ÿž] service-worker.js pre-populates the cache for some bundles that are not present on the current page

maiieul opened this issue ยท 3 comments

Which component is affected?

Qwik Rollup / Vite plugin

Describe the bug

This is a bug first encountered in Qwik UI in preview and prod. It seems to me to be a build issue, not sure if it's Rollup, Vite or the optimizer.

When our application has multiple entry files and multiple context providers, it seems that the service worker starts fetching and pre-populating the cache for some bundles that are not needed on the page.

image

As showcased in the screenshot, I understand that the context.id-DK1jWIYg.js containing the "context-2" context is downloaded through the service-worker and placed in the cache for later use. Is this the intended behavior? I feel like Qwik should be smart enough to understand that context-2 is not needed on page /1, and therefore should only be loaded on page /2.

Reproduction

https://github.com/maiieul/qwik-service-worker-dowloads-external-bundles

Steps to reproduce

  • pnpm i
  • pnpm preview

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M2
    Memory: 5.92 GB / 24.00 GB
    Shell: 3.7.0 - /opt/homebrew/bin/fish
  Binaries:
    Node: 21.7.3 - /opt/homebrew/bin/node
    npm: 10.5.0 - /opt/homebrew/bin/npm
    pnpm: 8.14.0 - /opt/homebrew/bin/pnpm
    bun: 1.1.0 - ~/.bun/bin/bun
  Browsers:
    Chrome: 124.0.6367.62
    Safari: 17.4.1
  npmPackages:
    @builder.io/qwik: ^1.5.2 => 1.5.2 
    @builder.io/qwik-city: ^1.5.2 => 1.5.2 
    undici: * => 6.13.0 
    vite: ^5.1.6 => 5.2.9 


### Additional Information

_No response_

Heads up ๐Ÿ‘†

The Qwik UI issue above (qwikifiers/qwik-ui#719) might give more context on the consequences of this issue.

I had that issue because of Cloudflare cache I used. Are you using cloudflare?