fix(cache): disable service worker to prevent stale cache on mobile

Flutter's PWA service worker caches the entire app shell aggressively,
causing users to see old versions even after deploys. Disabling it lets
nginx cache headers take effect. Also unregisters any existing service
worker already installed on user devices.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-02 14:48:05 -05:00
co-authored by Claude Sonnet 4.6
parent e56ec8619e
commit 13a99d4d34
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ COPY pubspec.yaml pubspec.lock ./
RUN flutter pub get RUN flutter pub get
COPY . . COPY . .
RUN flutter build web --release --base-href / RUN flutter build web --release --base-href / --pwa-strategy=none
# Stage 2: Serve with nginx # Stage 2: Serve with nginx
FROM nginx:alpine FROM nginx:alpine
+9
View File
@@ -89,6 +89,15 @@
}); });
</script> </script>
<script>
// Unregister any previously installed service worker so stale cache is cleared
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(regs) {
regs.forEach(function(r) { r.unregister(); });
});
}
</script>
<script> <script>
// Force cache busting: append build timestamp so stale JS/CSS is never reused // Force cache busting: append build timestamp so stale JS/CSS is never reused
var _v = new Date().getTime(); var _v = new Date().getTime();