Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[flutter_tools] Ensure service worker starts caching assets since fir…
Browse files Browse the repository at this point in the history
…st load (#116833)

* [Flutter_tools] Ensure service worker starts caching assets since the first launch

* [flutter_tools] add comment to give some context on self.clients.claim()

* [flutter_tools] add comment to give some context on self.clients.claim()
  • Loading branch information
david-landeros authored Jan 19, 2023
1 parent 99e4ca5 commit c5ceff1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 4 additions & 7 deletions dev/bots/service_worker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,8 @@ Future<void> runWebServiceWorkerTest({
'index.html': 2,
if (shouldExpectFlutterJs)
'flutter.js': 1,
// We still download some resources multiple times if the server is non-caching.
'main.dart.js': 2,
'assets/FontManifest.json': 2,
'main.dart.js': 1,
'assets/FontManifest.json': 1,
'flutter_service_worker.js': 1,
'assets/AssetManifest.json': 1,
'assets/fonts/MaterialIcons-Regular.otf': 1,
Expand Down Expand Up @@ -413,7 +412,6 @@ Future<void> runWebServiceWorkerTest({
if (shouldExpectFlutterJs)
'flutter.js': 1,
'flutter_service_worker.js': 1,
'assets/fonts/MaterialIcons-Regular.otf': 1,
'CLOSE': 1,
if (!headless)
'manifest.json': 1,
Expand All @@ -439,10 +437,9 @@ Future<void> runWebServiceWorkerTest({
if (shouldExpectFlutterJs)
'flutter.js': 1,
'flutter_service_worker.js': 2,
'main.dart.js': 2,
'main.dart.js': 1,
'assets/AssetManifest.json': 1,
'assets/FontManifest.json': 2,
'assets/fonts/MaterialIcons-Regular.otf': 1,
'assets/FontManifest.json': 1,
'CLOSE': 1,
if (!headless)
...<String, int>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ self.addEventListener("activate", function(event) {
await caches.delete(TEMP);
// Save the manifest to make future upgrades efficient.
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
// Claim client to enable caching on first launch
self.clients.claim();
return;
}
var oldManifest = await manifest.json();
Expand All @@ -95,6 +97,8 @@ self.addEventListener("activate", function(event) {
await caches.delete(TEMP);
// Save the manifest to make future upgrades efficient.
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
// Claim client to enable caching on first launch
self.clients.claim();
return;
} catch (err) {
// On an unhandled exception the state of the cache cannot be guaranteed.
Expand Down

0 comments on commit c5ceff1

Please sign in to comment.