I'm experiencing an issue with Flutter web service worker caching. When updating my Flutter web application, the service worker version in the flutter_bootstrap_js
gets updated, but the actual content doesn't reflect the changes immediately.
I'm using the Flutter web configuration where {{flutter_bootstrap_js}}
gets replaced with the actual bootstrap code in index.html
:
<script>
{{flutter_bootstrap_js}}
</script>
This correctly generates the updated service worker version in the code:
```javascript
_flutter.loader.load({
serviceWorkerSettings: {
serviceWorkerVersion: "382593536"
}
});
```
When the service worker version updates in flutter_bootstrap_js
, the changes should be reflected immediately after a refresh.
The old version persists despite the new service worker version being present in the code, and changes only appear after a significant delay (hours or next day).
Would appreciate any insights into this caching behavior and how to properly handle service worker updates in Flutter web applications.
Tags: flutter
flutter-web
service-worker
caching
web
When the service worker version updates in flutter_bootstrap_js
, the changes should be reflected immediately after a refresh.
The issue was related to Cloudflare caching, not the Flutter service worker itself. Here's what was happening and how to fix it:
Even though the service worker version was updating correctly in the flutter_bootstrap_js
, Cloudflare was serving cached versions of the assets, preventing the new version from being loaded immediately.
To resolve this issue, you need to:
Clear Cloudflare's cache:
(Optional) During development, you can:
Hope this helps others who might face similar issues with Flutter web deployments behind Cloudflare!
Tags: cloudflare
, flutter-web
, caching
, cdn