[flutter_tools] cache-bust in service worker (#56786)

This commit is contained in:
Jonah Williams
2020-05-16 14:57:04 -07:00
committed by GitHub
parent e7b6b52102
commit 631087d83b
7 changed files with 264 additions and 11 deletions

View File

@@ -0,0 +1,19 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
Future<void> main() async {
final html.ServiceWorkerRegistration worker = await html.window.navigator.serviceWorker.ready;
if (worker.active != null) {
await Future.delayed(const Duration(seconds: 5));
await html.HttpRequest.getString('CLOSE');
return;
}
worker.addEventListener('statechange', (event) async {
if (worker.active != null) {
await Future.delayed(const Duration(seconds: 5));
await html.HttpRequest.getString('CLOSE');
}
});
}

View File

@@ -5,6 +5,11 @@ environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.6.0 <3.0.0"
flutter:
assets:
- lib/a.dart
- lib/b.dart
dependencies:
flutter:
sdk: flutter

View File

@@ -2,12 +2,25 @@
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>web_integration</title>
<script defer src="main.dart.js" type="application/javascript"></script>
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<title>Web Test</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

View File

@@ -0,0 +1,12 @@
{
"name": "web_integration_test",
"short_name": "web_integration_test",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": []
}