[flutter_tools] register service worker after first frame event (#66082)

Registering the service worker immediately after the documented has loaded may cause SW initialization to compete with framework initialization. It was recommended to us that we defer the service worker setup until after the framework is done with setup, which should be sometime after the first frame.

To implement this, I augmented the binding setup to dispatch an event on the document after the binding has initialized. I don't see any obvious risks with this setup.

Fixes #66066
This commit is contained in:
Jonah Williams
2020-09-23 18:58:05 -07:00
committed by GitHub
parent 9bfab77835
commit 90d83e37a6
5 changed files with 50 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ found in the LICENSE file. -->
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
window.addEventListener('flutter-first-frame', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}