--- title: ServiceWorkerGlobalScope.oninstall slug: Web/API/ServiceWorkerGlobalScope/oninstall tags: - API - Property - Reference - Service Worker - ServiceWorker - ServiceWorkerGlobalScope - oninstall translation_of: Web/API/ServiceWorkerGlobalScope/oninstall ---
{{SeeCompatTable}}{{APIRef("Service Workers API")}}
{{domxref("ServiceWorkerGlobalScope")}} インターフェースの oninstall プロパティは、(Service Worker がインストールされたときの){{Event("install")}} イベントが発生するたびに発火するイベントハンドラーです。これはアクティブ化の前に発生します。
ServiceWorkerGlobalScope.oninstall = function(event) { ... };
ServiceWorkerGlobalScope.addEventListener('install', function(event) { ... });
次のスニペットは Using Service Workers のものです。詳細はそちらをご覧ください。
this.addEventListener('install', function(event) {
event.waitUntil(
caches.create('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'
);
})
);
});
| 仕様 | ステータス | コメント |
|---|---|---|
| {{SpecName('Service Workers', '#service-worker-global-scope-event-handlers', 'Event Handlers')}} | {{Spec2('Service Workers')}} | 初期定義。 |
{{Compat("api.ServiceWorkerGlobalScope.oninstall")}}