Skip to content

Commit

Permalink
Delegate cache control from Flutter to browser (#3289)
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora authored Nov 28, 2024
1 parent 2128a6e commit 9c3954a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
28 changes: 28 additions & 0 deletions docs/adr/0055-remove-flutter-service-worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 55. Remove Flutter Service Worker

Date: 2024-11-26

## Status

Accepted

## Context

- Flutter Service Worker have many issues regarding updating cache resources
- https://github.com/flutter/flutter/issues/104509
- https://github.com/flutter/flutter/issues/63500
- Flutter is moving away from Flutter Service Worker
- https://github.com/flutter/flutter/issues/156910

## Decision

- We remove the Flutter Service Worker and let the browser handle the cache by:
- Remove the Flutter Service Worker initialization
- Remove the existing Flutter Service Worker registration

## Consequences

- Twake Mail web now will validate cache with the server every time it is loaded
- If the status code is 200, new resources will be fetched
- If the status code is 304, old resources will be used
- All of the existing service workers will be removed, even if it is not Flutter Service Worker
36 changes: 27 additions & 9 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,33 @@

loadLanguageResources().finally(initialTmailApp);

_flutter.loader.load({
serviceWorkerSettings: {
serviceWorkerVersion: {{flutter_service_worker_version}},
},
onEntrypointLoaded: async function(engineInitializer) {
const appRunner = await engineInitializer.initializeEngine();
await appRunner.runApp();
}
});
if ('serviceWorker' in navigator) {
navigator
.serviceWorker
.getRegistrations()
.then(async function(registrations) {
try {
await Promise.all(registrations.map(function(registration) {
return registration.unregister();
}));
} catch (error) {
console.log('[Twake Mail] Error unregistering service worker: ', error);
}
_flutter.loader.load({
onEntrypointLoaded: async function(engineInitializer) {
const appRunner = await engineInitializer.initializeEngine();
await appRunner.runApp();
}
});
});
} else {
_flutter.loader.load({
onEntrypointLoaded: async function(engineInitializer) {
const appRunner = await engineInitializer.initializeEngine();
await appRunner.runApp();
}
});
}
</script>
<script src="https://unpkg.com/pica/dist/pica.min.js" ></script>
</body>
Expand Down

0 comments on commit 9c3954a

Please sign in to comment.