Unverified Commit c5ceff11 authored by David Landeros's avatar David Landeros Committed by GitHub

[flutter_tools] Ensure service worker starts caching assets since first 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()
parent 99e4ca50
...@@ -382,9 +382,8 @@ Future<void> runWebServiceWorkerTest({ ...@@ -382,9 +382,8 @@ Future<void> runWebServiceWorkerTest({
'index.html': 2, 'index.html': 2,
if (shouldExpectFlutterJs) if (shouldExpectFlutterJs)
'flutter.js': 1, 'flutter.js': 1,
// We still download some resources multiple times if the server is non-caching. 'main.dart.js': 1,
'main.dart.js': 2, 'assets/FontManifest.json': 1,
'assets/FontManifest.json': 2,
'flutter_service_worker.js': 1, 'flutter_service_worker.js': 1,
'assets/AssetManifest.json': 1, 'assets/AssetManifest.json': 1,
'assets/fonts/MaterialIcons-Regular.otf': 1, 'assets/fonts/MaterialIcons-Regular.otf': 1,
...@@ -413,7 +412,6 @@ Future<void> runWebServiceWorkerTest({ ...@@ -413,7 +412,6 @@ Future<void> runWebServiceWorkerTest({
if (shouldExpectFlutterJs) if (shouldExpectFlutterJs)
'flutter.js': 1, 'flutter.js': 1,
'flutter_service_worker.js': 1, 'flutter_service_worker.js': 1,
'assets/fonts/MaterialIcons-Regular.otf': 1,
'CLOSE': 1, 'CLOSE': 1,
if (!headless) if (!headless)
'manifest.json': 1, 'manifest.json': 1,
...@@ -439,10 +437,9 @@ Future<void> runWebServiceWorkerTest({ ...@@ -439,10 +437,9 @@ Future<void> runWebServiceWorkerTest({
if (shouldExpectFlutterJs) if (shouldExpectFlutterJs)
'flutter.js': 1, 'flutter.js': 1,
'flutter_service_worker.js': 2, 'flutter_service_worker.js': 2,
'main.dart.js': 2, 'main.dart.js': 1,
'assets/AssetManifest.json': 1, 'assets/AssetManifest.json': 1,
'assets/FontManifest.json': 2, 'assets/FontManifest.json': 1,
'assets/fonts/MaterialIcons-Regular.otf': 1,
'CLOSE': 1, 'CLOSE': 1,
if (!headless) if (!headless)
...<String, int>{ ...<String, int>{
......
...@@ -70,6 +70,8 @@ self.addEventListener("activate", function(event) { ...@@ -70,6 +70,8 @@ self.addEventListener("activate", function(event) {
await caches.delete(TEMP); await caches.delete(TEMP);
// Save the manifest to make future upgrades efficient. // Save the manifest to make future upgrades efficient.
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
// Claim client to enable caching on first launch
self.clients.claim();
return; return;
} }
var oldManifest = await manifest.json(); var oldManifest = await manifest.json();
...@@ -95,6 +97,8 @@ self.addEventListener("activate", function(event) { ...@@ -95,6 +97,8 @@ self.addEventListener("activate", function(event) {
await caches.delete(TEMP); await caches.delete(TEMP);
// Save the manifest to make future upgrades efficient. // Save the manifest to make future upgrades efficient.
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
// Claim client to enable caching on first launch
self.clients.claim();
return; return;
} catch (err) { } catch (err) {
// On an unhandled exception the state of the cache cannot be guaranteed. // On an unhandled exception the state of the cache cannot be guaranteed.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment