Repository: angular
Issue: Angular 17 with PWA fail always updating with "TOO MANY REDIRECTS"
Labels: area: service-worker

### Which @angular/* package(s) are the source of the bug?

service-worker

### Is this a regression?

Yes

### Description



# steps to recreate the error

1. `git clone https://github.com/hittten/pwaApp.git` and `npm i`
2. run `firebase init hosting`

```txt
=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add, 
but for now we'll just set up a default project.

? Please select an option: Use an existing project
? Select a default Firebase project for this directory: your-project-id (your-project-id)
i  Using project your-project-id (your-project-id)

=== Hosting Setup
? Detected an existing Angular codebase in the current directory, should we use this? Yes
? In which region would you like to host server-side content, if applicable? europe-west1 (Belgium)
? Set up automatic builds and deploys with GitHub? No

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

✔  Firebase initialization complete!
```

3. run `firebase deploy`
4. visit https://your-project-id.web.app
5. open the Javascript console and make sure that the network and application tabs are with the correct checkboxes:
<img width="548" alt="Captura de pantalla 2024-03-23 a las 23 36 13" src="https://github.com/angular/angular/assets/5982373/d4e9cc76-b9b5-4472-b615-e4bc17b17662">
<img width="597" alt="Captura de pantalla 2024-03-23 a las 23 36 26" src="https://github.com/angular/angular/assets/5982373/0a1f80fc-5cf4-4e0e-930f-c1d234b7fd7e">

6.  run `firebase deploy` again and after full deployment reloads the page. You will see everything as expected and with the update message
7.  edit `src/app/app.component.ts` and change the title property to a random string
8. run `firebase deploy` again and after full deployment reloads the page.
9. you will see the error:
<img width="1680" alt="Captura de pantalla 2024-03-23 a las 22 26 25" src="https://github.com/angular/angular/assets/5982373/f1c7e460-c1a9-484f-a558-3559d3be4ff9">


### Please provide a link to a minimal reproduction of the bug

https://github.com/hittten/pwaApp

### Please provide the exception or error you saw

```true
Response not Ok (fetchAndCacheOnce): request for https://your-project-id.web.app/index.html returned response 504 Gateway Timeout
Error: Response not Ok (fetchAndCacheOnce): request for https://your-project-id.web.app/index.html returned response 504 Gateway Timeout
    at PrefetchAssetGroup.fetchAndCacheOnce (https://your-project-id.web.app/ngsw-worker.js:432:17)
    at async https://your-project-id.web.app/ngsw-worker.js:535:9
    at async https://your-project-id.web.app/ngsw-worker.js:521:9
    at async https://your-project-id.web.app/ngsw-worker.js:521:9
    at async https://your-project-id.web.app/ngsw-worker.js:521:9
    at async https://your-project-id.web.app/ngsw-worker.js:521:9
    at async PrefetchAssetGroup.initializeFully (https://your-project-id.web.app/ngsw-worker.js:520:7)
    at async https://your-project-id.web.app/ngsw-worker.js:924:11
    at async AppVersion.initializeFully (https://your-project-id.web.app/ngsw-worker.js:923:9)
    at async Driver.setupUpdate (https://your-project-id.web.app/ngsw-worker.js:1623:9)
(anonymous) @ main-QZDSPL4N.js:7
next @ main-QZDSPL4N.js:3
_next @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
(anonymous) @ main-QZDSPL4N.js:3
_next @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
(anonymous) @ main-QZDSPL4N.js:3
bt @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
_next @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
(anonymous) @ main-QZDSPL4N.js:3
_next @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
(anonymous) @ main-QZDSPL4N.js:3
_next @ main-QZDSPL4N.js:3
next @ main-QZDSPL4N.js:3
a @ main-QZDSPL4N.js:3
invokeTask @ polyfills-RT5I6R6G.js:1
onInvokeTask @ main-QZDSPL4N.js:7
invokeTask @ polyfills-RT5I6R6G.js:1
runTask @ polyfills-RT5I6R6G.js:1
invokeTask @ polyfills-RT5I6R6G.js:1
O @ polyfills-RT5I6R6G.js:2
Z @ polyfills-RT5I6R6G.js:2
B @ polyfills-RT5I6R6G.js:2
```


### Please provide the environment you discovered this bug in (run `ng version`)

```true
Angular CLI: 17.3.1
Node: 20.11.1
Package Manager: npm 10.5.0
OS: darwin arm64

Angular: 17.3.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.1
@angular-devkit/build-angular   17.3.1
@angular-devkit/core            17.3.1
@angular-devkit/schematics      17.3.1
@schematics/angular             17.3.1
rxjs                            7.8.1
typescript                      5.4.3
zone.js                         0.14.4
```


### Anything else?

The error appears when you edit a file, if you deploy multiple versions with the same code without modifying anything, all the updates will be executed as they should.