| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/API/ServiceWorker | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2018 ..
* Some parts of this feature may have varying levels of support.
ServiceWorker, ServiceWorker API, Service Worker. Service Worker ( , Web Workers, ..), ServiceWorker.
ServiceWorker ServiceWorkerRegistration.active ServiceWorkerContainer.controller Service Worker, ( , Service Worker )
ServiceWorker : install activate , fetch. ServiceWorker ServiceWorker.state, .
ServiceWorker Worker.
ServiceWorker.scriptURL URL Service Worker. URL , , ServiceWorker.
ServiceWorker.state Service Worker. : installing, installed, activating, activated redundant.
ServiceWorker.onstatechange statechange; , ServiceWorker.state.
ServiceWorker Worker, Worker.terminate, Service Worker.
Service Worker (). ServiceWorker.state .
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("service-worker.js", {
scope: "./",
})
.then(function (registration) {
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
document.querySelector("#kind").textContent = "installing";
} else if (registration.waiting) {
serviceWorker = registration.waiting;
document.querySelector("#kind").textContent = "waiting";
} else if (registration.active) {
serviceWorker = registration.active;
document.querySelector("#kind").textContent = "active";
}
if (serviceWorker) {
// logState(serviceWorker.state);
serviceWorker.addEventListener("statechange", function (e) {
// logState(e.target.state);
});
}
})
.catch(function (error) {
// Service Worker.
// service-worker.js .
});
} else {
// Service Worker.
}
| Specification |
|---|
| Service Workers Nightly # serviceworker-interface |
This page was last modified on 17 . 2024 . by MDN contributors.
ServiceWorkerYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |