Skip to content

index.html should be excluded from service worker cache #474

@kimamula

Description

@kimamula

Do you want to request a feature or report a bug?

bug

What is the current behaviour?

bundle.{hash}.js tries to load the old version of route-{page}.chunk.{hash}.js when JS code is modified, which results in an error.

If the current behaviour is a bug, please provide the steps to reproduce.

  1. Create new project from template (I used material)
  2. Run the project on localhost ($ npm run serve)
    • The following JS files are created
      • bundle.2eb65.js
      • route-home.chunk.f678b.js
      • route-profile.chunk.c26a1.js
  3. Open https://localhost:8080 in browser
    • index.html, the JS files listed above, and other resources are cached by service worker
  4. Edit src/routes/profile/index.js (I added console.log('something has changed'); at render() method)
  5. Rerun $ npm run serve
    • The JS files are updated as follows
      • bundle.2eb65.js -> bundle.a5db3.js
      • route-home.chunk.f678b.js (unchanged)
      • route-profile.chunk.c26a1.js -> route-profile.chunk.27ce5.js
  6. Reload https://localhost:8080 in browser
    • index.html cached at the step 3 is used as the response for https://localhost:8080
    • Cached index.html requests bundle.2eb65.js (the old version), which is also restored from the service worker cache
    • In the background, service worker is updated and activated immediately due to skipWaiting(), which triggers deletion of the old caches (such as route-profile.chunk.c26a1.js)
  7. Click link to the Profile page
    • bundle.2eb65.js (the old version) requests route-profile.chunk.c26a1.js (the old version), which exists neither on the server nor in the service worker cache
      • At this point an error occurs.

What is the expected behaviour?

All the client side code should be updated to the latest version when JS code is modified.

Excluding index.html from the service worker cache (i.e., adding /index\.html$/ here), which prevents the old index.html from requesting the old bundle at the step 6-ii, should fix the problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions