Service Worker API
ë³´ì 컨í ì¤í¸: ì´ ê¸°ë¥ì ì¼ë¶ ëë 모ë ì§ì ë¸ë¼ì°ì ì ë³´ì 컨í ì¤í¸ (HTTPS)ììë§ ì¬ì©í ì ììµëë¤.
ìë¹ì¤ ì커ë ì¹ ìì© íë¡ê·¸ë¨, ë¸ë¼ì°ì , ê·¸ë¦¬ê³ (ì¬ì© ê°ë¥í ê²½ì°) ë¤í¸ìí¬ ì¬ì´ì íë¡ì ìë² ìí ì í©ëë¤. ìë¹ì¤ ì커ì ê°ë° ìëë ì¬ë¬ê°ì§ê° ìì§ë§, ê·¸ ì¤ììë í¨ê³¼ì ì¸ ì¤íë¼ì¸ ê²½íì ìì±íê³ , ë¤í¸ìí¬ ìì²ì ê°ë¡ì±ì ë¤í¸ìí¬ ì¬ì© ê°ë¥ ì¬ë¶ì ë°ë¼ ì ì í íëì ì·¨íê³ , ìë²ì ìì°ì ì ë°ì´í¸í ì ììµëë¤. ëí í¸ì ì림과 백그ë¼ì´ë ë기í APIë¡ì ì ê·¼ë ì ê³µí©ëë¤.
ìë¹ì¤ ì커ì ê°ë ê³¼ ì¬ì©ë²
ìë¹ì¤ ì커ë ì¶ì²ì ê²½ë¡ì ëí´ ë±ë¡íë ì´ë²¤í¸ ê¸°ë° ì커ë¡ì JavaScript íì¼ì íí를 ê°ê³ ììµëë¤. ìë¹ì¤ ì커ë ì°ê´ë ì¹ íì´ì§/ì¬ì´í¸ë¥¼ íµì íì¬ íìê³¼ 리ìì¤ ìì²ì ê°ë¡ì± ìì íê³ , 리ìì¤ë¥¼ êµì¥í ì¸ë¶ì ì¼ë¡ ìºì±í ì ììµëë¤. ì´ë¥¼ íµí´ ì¹ ì±ì´ ì´ë¤ ìí©ìì ì´ë»ê² ëìí´ì¼ íëì§ ìë²½íê² ë°ê¿ ì ììµëë¤. (ì ì¼ ëíì ì¸ ìí©ì ë¤í¸ìí¬ë¥¼ ì¬ì©íì§ ëª»í ëì ëë¤.)
ìë¹ì¤ ì커ë ì커 ë§¥ë½ìì ì¤íë기 ë문ì DOMì ì ê·¼í ì ììµëë¤. ëí ì±ì 구ëíë 주 JavaScriptìë ë¤ë¥¸ ì¤ë ëìì ëìíë¯ë¡ ì°ì°ì ê°ë¡ë§ì§ ììµëë¤(ë ¼ ë¸ë¡í¹). ìë¹ì¤ ì커ë ì¨ì í ë¹ë기ì ì¼ë¡ ì¤ê³ëì¼ë©°, ê·¸ë¡ ì¸í´ ë기ì XHRì´ë ì¹ ì ì¥ì ë±ì API를 ìë¹ì¤ ì커 ë´ìì ì¬ì©í ì ììµëë¤.
ìë¹ì¤ ì커ë ë³´ì ìì ì´ì ë¡ HTTPSììë§ ëìí©ëë¤. ë¤í¸ìí¬ ìì²ì ìì í ì ìë¤ë ì ìì ì¤ê°ì 공격ì êµì¥í ì·¨ì½í기 ë문ì ëë¤. ëí Firefoxììë ì¬ìí ë³´í¸ ëª¨ëìì Service Worker APIì ì ê·¼í ì ììµëë¤.
ì°¸ê³ : ìë¹ì¤ ì커ë 모ë ê²ì ì¸ë¶ì ì¼ë¡ íµì í ì ìë¤ë ì ìì AppCache ë± ì¤íë¼ì¸ì´ë ìºìì ì´ì ìëë³´ë¤ ì°ì를 ì í©ëë¤. ìë¹ì¤ ì커ë ê°ë°ìì ìë를 ì§ìíì§ ìì¼ë©°, ì측과 ë¹ëê°ì ë ë§ê°ì§ì§ë ì기 ë문ì ëë¤.
ì°¸ê³ : ìë¹ì¤ ì커ë ìëµì 기ë¤ë¦° í ì±ê³µ ëë ì¤í¨ ì¡ì ì ì¤ííë ê²½ì°ê° ë§ì¼ë¯ë¡ íë¡ë¯¸ì¤ë¥¼ ì ê·¹ì ì¼ë¡ ì¬ì©í©ëë¤.
ë±ë¡
ìë¹ì¤ ì커ë ServiceWorkerContainer.register() ë©ìë를 ì¬ì©í´ ì²ì ë±ë¡í©ëë¤. ì±ê³µì ì¼ë¡ ë±ë¡í ê²½ì° í´ë¼ì´ì¸í¸ê° ìë¹ì¤ ì커를 ë¤ì´ë¡ëíê³ , ì¶ì² ì ì²´ì ëí´ í¹ì ê°ë°ìê° ì§ì í í¹ì 주ìë¤ì ëí´ì ìë¹ì¤ ì커ì ì¤ì¹ì íì±í(ìë 구í ì°¸ê³ )를 ìëí©ëë¤.
ë¤ì´ë¡ë, ì¤ì¹, íì±í
ìë¹ì¤ ì커를 ì´í´ë³´ë©´ ë¤ìê³¼ ê°ì ìëª ì£¼ê¸°ë¥¼ ë³¼ ì ììµëë¤.
- ë¤ì´ë¡ë
- ì¤ì¹
- íì±í
ìë¹ì¤ ìì»¤ê° ì ì´íë ì¬ì´í¸/íì´ì§ì ì¬ì©ìê° ì²ì ì ê·¼íë ìê° ìë¹ì¤ ìì»¤ê° ì¦ì ë¤ì´ë¡ëë©ëë¤.
ìë¹ì¤ ì커ì ì ë°ì´í¸ë ë¤ì ê²½ì°ì ë°ìí©ëë¤.
- ë²ì ë´ íì´ì§ë¡ì íì ë°ì
- ìë¹ì¤ ì커ìì ì´ë²¤í¸ê° ë°ìíëë°, ìë¹ì¤ ì커를 ì´ì 24ìê° ë´ì ë¤ì´ë¡ëíì§ ìì ê²½ì°
ë¤ì´ë¡ëí íì¼ì´ ë ìë¡ì´ ë²ì ì¸ ê²½ì° ìë¹ì¤ ì커ì ì¤ì¹ë¥¼ ìëí©ëë¤. ë²ì ë¹êµë 기존 ìë¹ì¤ ì커 íì¼ê³¼ì ë°ì´í¸ ë¨ì ë¹êµ 결과를 ì¬ì©í©ëë¤. ì´ íì´ì§/ì¬ì´í¸ìì ìë¹ì¤ ì커를 ì²ì ë°ê²¬í ê²½ì°ìë "ìë¡ì´ ë²ì "ì¼ë¡ ì·¨ê¸í©ëë¤.
기존 ìë¹ì¤ ìì»¤ê° ìì¼ë©´ ì¤ì¹ë¥¼ ìëíê³ , ì¤ì¹ë¥¼ ì±ê³µíë©´ íì±íí©ëë¤.
기존ì ìë¹ì¤ ìì»¤ê° ì¡´ì¬íë ê²½ì°, ìë¡ì´ ë²ì ì 백그ë¼ì´ëìì ì¤ì¹íì§ë§ íì±íë ìì§ íì§ ììµëë¤. ì´ ìì ì ì커를 ë기 ì¤ì¸ ì커ë¼ê³ ë¶ë¦
ëë¤. ë기 ì¤ì¸ ì커ë ì´ì ë²ì ì ìë¹ì¤ ì커를 ì¬ì©íë íì´ì§ê° 모ë ë«í ê²½ì° íì±íëì´ íì± ìì»¤ê° ë©ëë¤. ServiceWorkerGlobalScope.skipWaiting()ì ì¬ì©í´ íì±í ì 차를 ë 빨리 ììí ì ìì¼ë©°, ìë¡ì´ íì± ì커ë Clients.claim()ì ì¬ì©í´ ì´ì íì´ì§ë¥¼ íìí ì ììµëë¤.
ìëª
주기 ì¤ ë°ìíë ì´ë²¤í¸ ì¤ íëë install ì´ë²¤í¸ì
ëë¤. ì´ ì´ë²¤í¸ì ëíì ì¸ ì¬ì© ë°©ë²ì, ì를 ë¤ë©´ ë´ì¥ ì ì¥ì API를 ì¬ì©í´ ìºì를 ë§ë¤ê³ , ì¤íë¼ì¸ ìí©ìì ì¬ì©í ìì°ì ì¤ë¹íë ë±, ìë¹ì¤ ì커ì ì¬ì©ì ì¤ë¹íë ê²ì
ëë¤.
activate ì´ë²¤í¸ë ììµëë¤. activateì ìì ììë 과거ì ìºì를 ì§ì°ê³ , 구ë²ì ìë¹ì¤ ì커ì ê´ë ¨ë í목ì ì²ìíë ë± ì¬ë¬ê°ì§ë¥¼ ì 리í기ì ì¢ìµëë¤.
ìë¹ì¤ ì커ë FetchEvent ì´ë²¤í¸ë¥¼ ì¬ì©í´ ìì²ì ìëµí ì ììµëë¤. FetchEvent.respondWith() ë©ìë를 ì¬ì©í´ ìì²ì ëí ìëµì ìíë ë°©ìì¼ë¡ ìì ë¡ê² ë°ê¾¸ì¸ì.
ì°¸ê³ :
installê³¼ activate ì´ë²¤í¸ ì²ë¦¬ë ìê°ì´ 꽤 걸릴 ìë ì기ì, ìë¹ì¤ ì커 ëª
ì¸ë waitUntil() ë©ìë를 ì ê³µí©ëë¤. installì´ë activateìì waitUntil()ì í¸ì¶íë©´ì 매ê°ë³ìë¡ íë¡ë¯¸ì¤ë¥¼ ì ê³µíë©´, ì±ê³µì ì¼ë¡ ì´íí기 ì ê¹ì§ë ê¸°ë¥ ì´ë²¤í¸ê° ë°ìíì§ ììµëë¤.
기본ì ì¸ ì²« ìë¹ì¤ ì커를 차근차근 ë§ëë ë°©ë²ì ìë¹ì¤ ì커 ì¬ì©í기ìì ì½ì´ë³¼ ì ììµëë¤.
ë¤ë¥¸ ì¬ì©ë² ìì´ëì´
ìë¹ì¤ ì커ì ì¤ê³ë ë¤ìê³¼ ê°ì ì©ëë¡ ì¬ì©íë ê²ë ê°ìíìµëë¤.
- 백그ë¼ì´ë ë°ì´í° ë기í.
- ë¤ë¥¸ ì¶ì²ììì 리ìì¤ ìì²ì ìëµ.
- ìì¹ì ë³´, ìì´ë¡ ì¼ì ë± ê³ì°ì ëì ë¹ì©ì´ ë¤ì´ê°ë ë¤ìì íì´ì§ìì í¨ê» ì¬ì©í ì ìëë¡ ë°ì´í° ì ë°ì´í¸ë¥¼ ì¤ìí.
- ê°ë° 목ì ì¼ë¡ì CoffeeScript, Less, CJS/AMD 모ë ë±ì ìì¡´ì± ê´ë¦¬ì ì»´íì¼.
- 백그ë¼ì´ë ìë¹ì¤ í .
- í¹ì URL í¨í´ì 기ë°í ì¬ì©ì ì§ì í í릿 ì ê³µ.
- ì±ë¥ í¥ì. ì¬ì§ ì¨ë²ì ë¤ì ì¬ì§ ëª ì¥ì²ë¼, ì¬ì©ìê° íìë¡ í ê²ì¼ë¡ ìê°ëë 리ìì¤ì í리íì¹ ë±.
미ëì ìë¹ì¤ ì커ë ì¹ íë«í¼ì´ ë¤ì´í°ë¸ ì±ì ë¥ë ¥ì ë³´ë¤ ê·¼ì íëë¡ ì¬ë¬ ê°ì§ ì ì©í 기ë¥ì ìíí ì ìì ê²ì ëë¤. í¥ë¯¸ë¡ê²ë ë¤ë¥¸ ëª ì¸ììë ìë¹ì¤ ì커 ë§¥ë½ì ì¬ì©í ì ìì¼ë©°, ì´ë¯¸ ë¤ìê³¼ ê°ì ê³³ìì ì¬ì©íê³ ììµëë¤.
- 백그ë¼ì´ë ë기í: ì무 ì¬ì©ìë ì¬ì´í¸ì ìì ë ìë¹ì¤ ì커를 ê°ëí´ ìºì를 ì ë°ì´í¸ íë ë±ì ìì ì ìí.
- í¸ì ë©ìì§ì ë°ì: ìë¹ì¤ ì커를 ê°ë, ìë¡ì´ ì½í ì¸ ê° ì´ì© ê°ë¥íë¤ë ë©ìì§ë¥¼ ì¬ì©ììê² ì ì¡.
- í¹ì ìê°ê³¼ ë ì§ì ë°ì.
- ì§ì¤íì¤ ì§ì .
ì¸í°íì´ì¤
Cache-
ServiceWorkerìëª ì£¼ê¸°ì ì¼ë¶ë¡ì ìºìëëRequest/Responseê°ì²´ ìì ì ì¥ì를 ëíë ëë¤. CacheStorage-
Cacheê°ì²´ì ì ì¥ì를 ëíë ëë¤.ServiceWorkerê° ì ê·¼í ì ìë 모ë ì ëª ìºìì 주 ëë í 리를 ì ê³µíë©°,Cacheê°ì²´ë¥¼ ê°ë¦¬í¤ë 문ìì´ ì´ë¦ì ë§µíë ê´ë¦¬í©ëë¤. Client-
ìë¹ì¤ ì커 í´ë¼ì´ì¸í¸ì ë²ì를 ëíë ëë¤. ìë¹ì¤ ì커 í´ë¼ì´ì¸í¸ë ë¸ë¼ì°ì ë§¥ë½ììì 문ìì´ê±°ë, íì±íë ìì»¤ê° ì ì´íë
SharedWorkerì ëë¤. Clients-
Clientê°ì²´ì 목ë¡ì ëíë ëë¤. Clientsë íì¬ ì¶ì²ì íì± ìë¹ì¤ ì커 í´ë¼ì´ì¸í¸ì ì ê·¼íë 주ì ë°©ë²ì ëë¤. ExtendableEvent-
ìë¹ì¤ ì커 ìëª ì£¼ê¸°ì ì¼ë¶ë¡ì
ServiceWorkerGlobalScopeìì ë°ìíëinstallê³¼activateì´ë²¤í¸ì ì§ììê°ì ë립ëë¤. ì´ë¡ì¨ ë°ì´í°ë² ì´ì¤ ì¤í¤ë§ë¥¼ ì ê·¸ë ì´ëíê±°ë, ë§ë£ë ìºì í목ì ì§ì°ë ìì ë±ì´ ëë기 ì ê¹ì§FetchEventì ê°ì ê¸°ë¥ ì´ë²¤í¸ê°ServiceWorkerë¡ ì ë¬ëì§ ìëë¡ í©ëë¤. ExtendableMessageEvent-
The event object of a
messageevent fired on a service worker (when a channel message is received on theServiceWorkerGlobalScopefrom another context) â extends the lifetime of such events. FetchEvent-
The parameter passed into the
ServiceWorkerGlobalScope.onfetchhandler,FetchEventrepresents a fetch action that is dispatched on theServiceWorkerGlobalScopeof aServiceWorker. It contains information about the request and resulting response, and provides theFetchEvent.respondWith()method, which allows us to provide an arbitrary response back to the controlled page. InstallEvent-
The parameter passed into the
oninstallhandler, theInstallEventinterface represents an install action that is dispatched on theServiceWorkerGlobalScopeof aServiceWorker. As a child ofExtendableEvent, it ensures that functional events such asFetchEventare not dispatched during installation. -
Provides methods for managing the preloading of resources with a service worker.
-
Returns a
ServiceWorkerContainerobject, which provides access to registration, removal, upgrade, and communication with theServiceWorkerobjects for the associated document. NotificationEvent-
The parameter passed into the
onnotificationclickhandler, theNotificationEventinterface represents a notification click event that is dispatched on theServiceWorkerGlobalScopeof aServiceWorker. ServiceWorker-
Represents a service worker. Multiple browsing contexts (e.g. pages, workers, etc.) can be associated with the same
ServiceWorkerobject. ServiceWorkerContainer-
Provides an object representing the service worker as an overall unit in the network ecosystem, including facilities to register, unregister, and update service workers, and access the state of service workers and their registrations.
ServiceWorkerGlobalScope-
Represents the global execution context of a service worker.
ServiceWorkerMessageEvent-
Represents a message sent to a
ServiceWorkerGlobalScope. Note that this interface is deprecated in modern browsers. Service worker messages will now use theMessageEventinterface, for consistency with other web messaging features. ServiceWorkerRegistration-
Represents a service worker registration.
ServiceWorkerState-
Associated with its
ServiceWorker's state. SyncEvent-
The SyncEvent interface represents a sync action that is dispatched on the
ServiceWorkerGlobalScopeof a ServiceWorker. SyncManager-
Provides an interface for registering and listing sync registrations.
WindowClient-
Represents the scope of a service worker client that is a document in a browser context, controlled by an active worker. This is a special type of
Clientobject, with some additional methods and properties available.
ëª ì¸
| Specification |
|---|
| Service Workers Nightly> |