From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../activate_event/index.html | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 files/ja/web/api/serviceworkerglobalscope/activate_event/index.html (limited to 'files/ja/web/api/serviceworkerglobalscope/activate_event') diff --git a/files/ja/web/api/serviceworkerglobalscope/activate_event/index.html b/files/ja/web/api/serviceworkerglobalscope/activate_event/index.html new file mode 100644 index 0000000000..da64121d50 --- /dev/null +++ b/files/ja/web/api/serviceworkerglobalscope/activate_event/index.html @@ -0,0 +1,89 @@ +--- +title: 'ServiceWorkerGlobalScope: activate イベント' +slug: Web/API/ServiceWorkerGlobalScope/activate_event +tags: + - API + - Reference + - Service Workers + - ServiceWorkerGlobalScope + - activate + - events +translation_of: Web/API/ServiceWorkerGlobalScope/activate_event +--- +

{{DefaultAPISidebar("Service Workers API")}}

+ +

{{domxref("ServiceWorkerGlobalScope")}} インターフェイスの activate イベントは、{{domxref("ServiceWorkerRegistration")}} が新しいアクティブワーカー({{domxref("ServiceWorkerRegistration.active")}} worker)を取得すると発生します。

+ + + + + + + + + + + + + + + + + + + + +
バブリングなし
キャンセル不可
インターフェイス{{domxref("ExtendableEvent")}}
イベントハンドラープロパティ{{domxref("ServiceWorkerGlobalScope.onactivate")}}
+ +

+ +

次のスニペットは、activate イベントハンドラーを使用してキャッシュをアップグレードする方法を示しています。

+ +
globalScope.addEventListener('activate', function(event) {
+  var cacheWhitelist = ['v2'];
+
+  event.waitUntil(
+    caches.forEach(function(cache, cacheName) {
+      if (cacheWhitelist.indexOf(cacheName) == -1) {
+        return caches.delete(cacheName);
+      }
+    })
+  );
+});
+ +

次のように {{domxref("ServiceWorkerGlobalScope.onactivate")}} プロパティを使用してイベントハンドラーを設定することもできます。

+ +
globalScope.onactivate = function(event) {
+  ...
+};
+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('Service Workers', '#service-worker-global-scope-activate-event', 'activate')}}{{Spec2('Service Workers')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.ServiceWorkerGlobalScope.activate_event")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf