mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] automatically update to latest sw on install (#65784)
If a new service worker is installed, automatically update this behind the scenes. Immediately after a page refresh, the new worker and cache will be available, though the main.dart.js and others will be available sooner due to the cache busting URLS
This commit is contained in:
parent
2acd170814
commit
73652a723b
@ -476,6 +476,7 @@ const CORE = [
|
|||||||
${coreBundle.map((String file) => '"$file"').join(',\n')}];
|
${coreBundle.map((String file) => '"$file"').join(',\n')}];
|
||||||
// During install, the TEMP cache is populated with the application shell files.
|
// During install, the TEMP cache is populated with the application shell files.
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
|
skipWaiting();
|
||||||
return event.waitUntil(
|
return event.waitUntil(
|
||||||
caches.open(TEMP).then((cache) => {
|
caches.open(TEMP).then((cache) => {
|
||||||
return cache.addAll(
|
return cache.addAll(
|
||||||
@ -579,10 +580,12 @@ self.addEventListener('message', (event) => {
|
|||||||
// SkipWaiting can be used to immediately activate a waiting service worker.
|
// SkipWaiting can be used to immediately activate a waiting service worker.
|
||||||
// This will also require a page refresh triggered by the main worker.
|
// This will also require a page refresh triggered by the main worker.
|
||||||
if (event.data === 'skipWaiting') {
|
if (event.data === 'skipWaiting') {
|
||||||
return self.skipWaiting();
|
skipWaiting();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (event.message === 'downloadOffline') {
|
if (event.data === 'downloadOffline') {
|
||||||
downloadOffline();
|
downloadOffline();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -628,5 +631,11 @@ function onlineFirst(event) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function skipWaiting() {
|
||||||
|
if (self.skipWaiting != undefined) {
|
||||||
|
self.skipWaiting();
|
||||||
|
}
|
||||||
|
}
|
||||||
''';
|
''';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user