Repository: flutter
Issue: "Error: prepareServiceWorker took more than 4000ms to resolve. Moving on." when using --pwa-strategy=none after upgrading
Labels: platform-web,a: build,has reproducible steps,P2,team-web,triaged-web,found in release: 3.22,found in release: 3.24

### Steps to reproduce

1. `flutter create bug`
2. `cd bug/`
3. `flutter build web --build-name=1.0.0 --build-number=1 --pwa-strategy=none`
5. `cd build/web/`
6. `dhttpd`
8. Load the website (http://localhost:8080/) in your browser and close the browser.
9. `cd ../../`
10. `flutter build web --build-name=1.0.0 --build-number=2 --pwa-strategy=none`
11. `cd build/web/`
12. `dhttpd`
13. Open your browser and load the website. Observe the error.

The issue is the same as https://github.com/flutter/flutter/issues/134806, but at that time I didn't know how to reproduce it correctly.

dhttpd can be installed with `flutter pub global activate dhttpd`.

### Expected results

The website should not take extra 4 seconds to load when a new version is available.

### Actual results

The website takes 4 seconds extra to load when it is a newer version than the one that was loaded last time the website was visited.

### Code sample

<details open><summary>Code sample</summary>

Code generated with `flutter create bug` can be used.

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

Chrome:
![image](https://github.com/user-attachments/assets/1b1eadc1-998f-4175-a734-78dbd8ea644c)

</details>


### Logs

<details open><summary>Logs</summary>

```console
flutter_bootstrap.js:3 Exception while loading service worker: Error: prepareServiceWorker took more than 4000ms to resolve. Moving on.
    at flutter_bootstrap.js:1:2586
(anonymous) @ flutter_bootstrap.js:3
Promise.catch (async)
load @ flutter_bootstrap.js:3
(anonymous) @ flutter_bootstrap.js:12
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.22.3, on Ubuntu 23.04 6.2.0-39-generic, locale en_US.UTF-8)
    • Flutter version 3.22.3 on channel stable at /home/cup/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0850beeb2 (4 days ago), 2024-07-16 21:43:41 -0700
    • Engine revision 235db911ba
    • Dart version 3.4.4
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/cup/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/cup/apps/android-studio-2022.3.1.18-linux/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.3)
    • Android Studio at /home/cup/apps/android-studio-2022.3.1.18-linux/android-studio
    • Flutter plugin version 75.1.2
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2024.1)
    • IntelliJ at /snap/intellij-idea-community/515
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.91.1)
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension version 3.92.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 23.04 6.2.0-39-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 126.0.6478.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!

```

</details>