Baseline Widely available *
Service Worker APIì ServiceWorker
ì¸í°íì´ì¤ë ìë¹ì¤ ì커ë¡ì 참조를 ì ê³µí©ëë¤. ë¤ìì ë¸ë¼ì°ì§ ë§¥ë½(e.g. íì´ì§, ë¤ë¥¸ ì커, ë±ë±)ë ê³ ì í ServiceWorker
ê°ì²´ë¥¼ íµí´ ëì¼í ìë¹ì¤ ì커ì ì°ê²°í ì ììµëë¤.
ServiceWorker
ê°ì²´ë ServiceWorkerRegistration.active
ìì±ê³¼ ServiceWorkerContainer.controller
ìì±ì¼ë¡ ì ê·¼í ì ììµëë¤. controller
ë íì±íëì´ íì´ì§ë¥¼ íµì ì¤ì¸ ìë¹ì¤ ì커ì
ëë¤.
ServiceWorker
ì¸í°íì´ì¤ììë ì¼ë ¨ì ìëª
주기 ì´ë²¤í¸(install
, activate
)ì ê¸°ë¥ ì´ë²¤í¸(fetch
)ê° ë°ìí©ëë¤. ServiceWorker
ê°ì²´ì ìëª
주기ë ServiceWorker.state
ìì±ì´ ë´ê³ ììµëë¤.
ServiceWorker
ì¸í°íì´ì¤ë ë¶ëª¨ Worker
ìì ìì±ì ììí©ëë¤.
ServiceWorker.scriptURL
ì½ê¸° ì ì©
Returns the ServiceWorker
serialized script URL defined as part of ServiceWorkerRegistration
. The URL must be on the same origin as the document that registers the ServiceWorker
.
ServiceWorker.state
ì½ê¸° ì ì©
Returns the state of the service worker. It returns one of the following values: installing
, installed,
activating
, activated
, or redundant
.
ServiceWorker.onstatechange
ì½ê¸° ì ì©
An EventListener
property called whenever an event of type statechange
is fired; it is basically fired anytime the ServiceWorker.state
changes.
ServiceWorker
ì¸í°íì´ì¤ë ë¶ëª¨ Worker
ìì ë©ìë를 ììí©ëë¤. ë¨, Worker.terminate()
ë ìì¸ì´ë©° ìë¹ì¤ ì커ìì ì ê·¼í ì ììµëë¤.
This code snippet is from the service worker registration-events sample (live demo). The code listens for any change in the ServiceWorker.state
and returns its value.
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) {
// Something went wrong during registration. The service-worker.js file
// might be unavailable or contain a syntax error.
});
} else {
// The current browser doesn't support service workers.
}
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4