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.

Service worker returning outdated index.html

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/service-worker

Description

I have a problem with the Angular service worker returning an old version of index.html (from the date the service worker was installed) that is driving me bonkers!

Basically on a fresh startup of the browser (chrome) the old index.html is being served by the service worker resulting in a defunct mainxxx.js being loaded and due to the IIS rewrite rule I have in play to support deep linking, mainxxx.js returns back with the contents of index.html (side effect of service worker returning wrong index.html in first place)

When I soft or hard refresh the browser tab, the correct index.html is loaded and all is fine… that is, until I close the browser and start again at which point the old index.html is served up again 😮

I am a side-by-side deployment strategy, which basically means that a new folder is created every time ther eis a new deploy and the web hosting is then pointed at this new folder, thus the old files are not available while hosting the new deploy!

As you can see from the screenshot below (sorry about the redaction), I have turned off caching via the cache-control header for the index.html page and other service worker related files…

devtools

The below is a copy of my ngsw-config.json { "index": "/index.html", "assetGroups": [{ "name": "app", "installMode": "prefetch", "resources": { "files": [ "/favicon.ico", "/index.html", "/*.css", "/*.js" ] } }, { "name": "assets", "installMode": "lazy", "updateMode": "prefetch", "resources": { "files": [ "/assets/**" ] } }] }

🔬 Minimal Reproduction

Not sure how I can easily replicate as it requires publishing a few different versions etc!

🌍 Your Environment

Angular Version:



Angular CLI: 7.0.6
Node: 10.10.0
OS: darwin x64
Angular: 7.1.0
... animations, common, compiler, compiler-cli, core, forms

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.10.6
@angular-devkit/build-angular       0.10.6
@angular-devkit/build-optimizer     0.10.6
@angular-devkit/build-webpack       0.10.6
@angular-devkit/core                7.0.6
@angular-devkit/schematics          7.0.6
@angular/cli                        7.0.6
@angular/http                       7.1.3
@angular/language-service           7.1.3
@angular/platform-browser           7.1.3
@angular/platform-browser-dynamic   7.1.3
@angular/pwa                        0.8.8
@angular/router                     7.1.3
@angular/service-worker             7.1.3
@ngtools/webpack                    7.0.6
@schematics/angular                 0.8.8
@schematics/update                  0.10.6
rxjs                                6.3.3
typescript                          3.1.6
webpack                             4.19.1


Anything else relevant? I’ve only testing in chrome so far.

  • I’ve tried with an incognito tab mode where everything works as required
  • Clearing down the service work cache works… but not suitable for end users
  • uninstalling the service worker works… but not suitable for end users

It’s also been suggested via my overflow question that having the dev tools (inspector) window open could be causing the issue, though this is happening in production where the user does not have the dev tools open!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, May 26, 2020

There doesn’t seem to be anything unexpected there. Basically, the SW is correctly entering a degraded (EXISTING_CLIENTS_ONLY) state (since it is getting a 200 request for a hashed file but with different than expected content). What this means is that:

  1. Other clients (e.g. opening a second tab or reloading the current tab) should not be handled by the SW (but passed through to the network).
  2. The latest manifest should be fetched, so clients would be served by that in the future.

But that is what should happen theoretically 😁 The actual behavior might defer (e.g. due to a bug).

Feel free to send more info to my e-mail.

BTW, I would highly recommend not serving index.html for requests to files (e.g. URLs whose last path segment contains a dot (.)), because that can cause all sorts of funny issues (with and without SW).

0reactions
angular-automatic-lock-bot[bot]commented, Jun 26, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop service worker returning outdated index.html?
I have a problem with the Angular service worker returning an old version of index.html (from the date the service worker was installed) ......
Read more >
How to clear a service worker cache for index.html page?
I just inherited a website where the whole site (including index.html) is cached by a service worker. I deleted the old website and...
Read more >
Using Service Workers - Web APIs | MDN
Deleting old caches​​ While there are open pages that are controlled by the previous version of the worker, you need to keep both...
Read more >
Add a Service Worker to Your Site - CSS-Tricks
A service worker is a special type of JavaScript file that acts like middleware for your site. ... 'same-origin') return; // HTML files...
Read more >
Service worker configuration - Angular
Usually this is /index.html . assetGroups link. Assets are resources that are part of the application version that update along with the application....
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