ServiceWorkerGlobalScope: install event
ServiceWorkerGlobalScope
インターフェイスの install
イベントは、ServiceWorkerRegistration
が新しいインストール中のワーカー(ServiceWorkerRegistration.installing
worker)を取得すると発生します。
バブリング | なし |
---|---|
キャンセル | 不可 |
インターフェイス | ExtendableEvent |
イベントハンドラープロパティ | ServiceWorkerGlobalScope.oninstall |
例
次のスニペットは、install
イベントハンドラーを使用してキャッシュに多数のレスポンスを設定する方法を示しています。 サービスワーカーはこれを使用して、資産をオフラインで提供できます。
this.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.add(
'/sw-test/',
'/sw-test/index.html',
'/sw-test/style.css',
'/sw-test/app.js',
'/sw-test/image-list.js',
'/sw-test/star-wars-logo.jpg',
'/sw-test/gallery/',
'/sw-test/gallery/bountyHunters.jpg',
'/sw-test/gallery/myLittleVader.jpg',
'/sw-test/gallery/snowTroopers.jpg'
);
})
);
});
次のように ServiceWorkerGlobalScope.oninstall
プロパティを使用してイベントハンドラーを設定することもできます。
globalScope.oninstall = function(event) {
...
};
仕様
仕様 | 状態 | コメント |
---|---|---|
Service Workers install の定義 |
草案 |
ブラウザーの互換性
BCD tables only load in the browser