SlideShare a Scribd company logo
1 of 20
Download to read offline
Service Workers
기초 및 활용
Jungkee Song
Github: https://github.com/jungkees
Twitter: @jungkees
Google+: +JungkeeSong
Facebook: https://www.facebook.com/jungkees
Service Worker 가 해결하는 문제들
• 웹의 오프라인 사용성
- 오프라인 우선 (Offline-first)
- 개발자가 원하는대로!
개발자가 프로그래밍을 통하여 컨트롤 하는 Cache
개발자가 직접 작성하는 HTTP request 프록시
• 백그라운드 프로세싱
- 브라우저가 실행 중이지 않을 때도 이벤트 처리를 하고 싶다!
- Push notification, System alarm, BackgroundSync …
표준개발 현황
W3C Working Draft
[ED] https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
[Github] https://github.com/slightlyoff/ServiceWorker
이벤트 기반으로 동작하는 Worker
Service Worker는 브라우저에 의해 언제든지 종료 될 수 있음
fetch event
Navigation/Resource request
onfetch
Page
SW
Cache
self.caches.match(url)
Promise<response>
e.respondWith
(Promise<response>)
Page Page
Navigation/Resource request
fetch event
e.respondWith
(Promise<response>)
개발자가 프로그래밍으로 컨트롤 하는 Cache
Cache / CacheStorage 오프젝트 활용
Cache 오브젝트 메소드 참조
caches.open(“myCache”).then(function(cache) { … })
설계 및 동작 원리
• Same origin 기반으로 동작
• URL scope 이 registration 을 식별하는 key가 됨
• Client request 시 matching 되는 SW 에 의해 control 시작 됨
• Registration 은 installing / waiting / active worker를 가짐
• Lifecycle 이벤트: install, activate
• Functional 이벤트: fetch, push, sync 등
• Document 또는 Worker 가 Client 가 됨
• Client 가 register 를 요청하여 브라우저에 install 됨
• Resource request 시 선택된 SW 에 의해 control 됨
• HTTPS 필수
Client request
Client 가 client request 시 SW registration 을 선택함
onfetch
sw.js
Cache
self.caches.match(url)
Promise<response>
e.respondWith
(Promise<response>)
“/” /sw.js
[ Registration map ]
Scope Script URL
“/foo/” /foo/sw.js
Page
Navigate to https://example.com/index.html
fetch event
Scope matching
Run SW
Resource request
Control 되고 있는 client 는 resource request 시 해당 SW를 사용함
onfetch
sw.js
Cache
self.caches.match(url)
Promise<response>
e.respondWith
(Promise<response>)
“/” /sw.js
[ Registration map ]
Scope Script URL
“/foo/” /foo/sw.js
Page
Fetch “https://example.com/img/flower.png
fetch event
Control
Run SW
Registration
Client 에서 수행
// scope 은 default로 script의 위치와 동일한 url로 설정 됨
navigator.serviceWorker.register("/assets/v1/serviceworker.js").then(
function(registration) {
console.log("success!");
registration.installing.postMessage(“Howdy from your installing page.");
}, function(why) {
console.error("Installing the worker failed!", why);
});
“/assets/v1/” /assets/v1/serviceworker.js
[ Registration map ]
Scope Script URL
Registration
Client 에서 수행
[ Registration map ]
Scope Script URL
navigator.serviceWorker.register(“/sw.js”, { scope: “/bar/” });
“/bar/” /sw.js
“/foo/” /foo/sw.js
“/bar/” /bar/sw.js
navigator.serviceWorker.register("/foo/sw.js", { scope: “/foo/” });
navigator.serviceWorker.register("/bar/sw.js");
Service Worker 상태 변화
Service Worker 생명주기
HTML5 Rocks Introduction to Service Worker 내용 중
서비스워커 생명주기 단락을 참조해 보자
Install 과정: oninstall / onactivate
• 브라우저가 SW에 install 이벤트를 발생 시켜줌
- 개발자가 App에 필요한 resource를 미리 Caching할 수 있는 시간
• Event handler 안에서 event.waitUntil(promise) 를 활용하
여 promise를 통해 추상화 된 해당 동작이 resolve될 때까지
SW의 lifetime을 늘일 수 있음
• 브라우저가 SW에 activate 이벤트를 발생 시켜줌
- 개발자가 갱신이 필요한 resource를 정리할 수 있는 시간
oninstall
SW script fetch및 실행이 성공적으로 이루어 지면
install 이벤트가 service worker 에 dispatch 됨
Jake Archibald’s “The offline cookbook” 중
1-1/1-2 On install 참조
onactivate
waiting worker 가 activation 될 조건이 만족될 때
activate 이벤트가 service worker 에 dispatch 됨
Jake Archibald’s “The offline cookbook” 중
1-3. On activate 참조
Fetch 이벤트 핸들링: onfetch
Client / resource request 발생시 마다 fetch 이벤트
가 Service Worker 에 dispatch 됨
Jake Archibald’s “The offline cookbook” 중
1-6. Stale-while-revalidate 참조
Service Worker Update 발생 경로
• navigator.serviceWorker.register() API 명시적 호출
• 브라우저에 의한 자동 Update
• 매 client request 처리 시
• register.update() API의 명시적 호출
Update 동작
모든 client가 unload 되기 전에는 기존 active worker를 그대로 사용
onfetch
sw-v2
Cache
self.caches.match(url)
Promise<response>
e.respondWith
(Promise<response>)
“/” /sw-v1
[ Registration map ]
Scope active
fetch event
-
waiting
Page
sw-v1
Update
Install
Page
sw-v1
/sw-v2 /sw-v2-
Page
sw-v2
Fetch “https://example.com/img/flower.png
Run SW
브라우저 지원 현황
Chrome 40+
Firefox nightly
Under consideration
40에서는 Cache, Client 지원하지 않음
IE
Partial under flag
about:config > dom.serviceWorkers.enabled
Jake’s “Is ServiceWorker ready?”
Stay alerted!
Cache polyfill 활용 가능
참고자료
Service Worker - first draft published - Jake Archibald
Specification
Github’s explainer
Github’s implementation considerations
Introduction to Service Worker - Matt Gaunt (번역: 도창욱)
The offline cookbook - Jake Archibald
Push Notifications & Service Worker

More Related Content

What's hot

Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나JeongHun Byeon
 
Vuejs 시작하기
Vuejs 시작하기Vuejs 시작하기
Vuejs 시작하기성일 한
 
혁신적인 웹컴포넌트 라이브러리 - Polymer
혁신적인 웹컴포넌트 라이브러리 - Polymer혁신적인 웹컴포넌트 라이브러리 - Polymer
혁신적인 웹컴포넌트 라이브러리 - PolymerJae Sung Park
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.jsWoo Jin Kim
 
iOS App 개발 with React Native + ClojureScript
iOS App 개발 with React Native + ClojureScriptiOS App 개발 with React Native + ClojureScript
iOS App 개발 with React Native + ClojureScriptCheolhee Han
 
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)ChanMin Park
 
Node.js
Node.jsNode.js
Node.jsymtech
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 PreviewJuntai Park
 
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기XpressEngine
 
웹 2.0 기술 소개 (2006)
웹 2.0 기술 소개 (2006)웹 2.0 기술 소개 (2006)
웹 2.0 기술 소개 (2006)Channy Yun
 
웹 Front-End 실무 이야기
웹 Front-End 실무 이야기웹 Front-End 실무 이야기
웹 Front-End 실무 이야기JinKwon Lee
 
파크히어 Realm 사용 사례
파크히어 Realm 사용 사례파크히어 Realm 사용 사례
파크히어 Realm 사용 사례선협 이
 
Springcamp spring boot intro
Springcamp spring boot introSpringcamp spring boot intro
Springcamp spring boot introJae-il Lee
 
[123] electron 김성훈
[123] electron 김성훈[123] electron 김성훈
[123] electron 김성훈NAVER D2
 
Html5 web workers
Html5 web workersHtml5 web workers
Html5 web workersWoo Jin Kim
 
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기Chang W. Doh
 

What's hot (20)

Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나
 
Vuejs 시작하기
Vuejs 시작하기Vuejs 시작하기
Vuejs 시작하기
 
혁신적인 웹컴포넌트 라이브러리 - Polymer
혁신적인 웹컴포넌트 라이브러리 - Polymer혁신적인 웹컴포넌트 라이브러리 - Polymer
혁신적인 웹컴포넌트 라이브러리 - Polymer
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.js
 
Deview2013 track1 session7
Deview2013 track1 session7Deview2013 track1 session7
Deview2013 track1 session7
 
iOS App 개발 with React Native + ClojureScript
iOS App 개발 with React Native + ClojureScriptiOS App 개발 with React Native + ClojureScript
iOS App 개발 with React Native + ClojureScript
 
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)
서버리스 기반의 프론트엔드 서버 구축(Serverless frontend web server)
 
Node.js
Node.jsNode.js
Node.js
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 Preview
 
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기
XECon2015 :: [2-2] 박상현 - React로 개발하는 SPA 실무 이야기
 
웹 2.0 기술 소개 (2006)
웹 2.0 기술 소개 (2006)웹 2.0 기술 소개 (2006)
웹 2.0 기술 소개 (2006)
 
웹 Front-End 실무 이야기
웹 Front-End 실무 이야기웹 Front-End 실무 이야기
웹 Front-End 실무 이야기
 
파크히어 Realm 사용 사례
파크히어 Realm 사용 사례파크히어 Realm 사용 사례
파크히어 Realm 사용 사례
 
iOS9 소개
iOS9 소개iOS9 소개
iOS9 소개
 
Springcamp spring boot intro
Springcamp spring boot introSpringcamp spring boot intro
Springcamp spring boot intro
 
[123] electron 김성훈
[123] electron 김성훈[123] electron 김성훈
[123] electron 김성훈
 
How to Grunt.js
How to Grunt.jsHow to Grunt.js
How to Grunt.js
 
React Redux React Native
React Redux React NativeReact Redux React Native
React Redux React Native
 
Html5 web workers
Html5 web workersHtml5 web workers
Html5 web workers
 
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기
프론트엔드 개발자를 위한 크롬 렌더링 성능인자 이해하기
 

Viewers also liked

HyWAI Web Bluetooth API
HyWAI Web Bluetooth APIHyWAI Web Bluetooth API
HyWAI Web Bluetooth APIJonathan Jeon
 
Service Worker 101 (한국어)
Service Worker 101 (한국어)Service Worker 101 (한국어)
Service Worker 101 (한국어)Chang W. Doh
 
Service Worker 201 (한국어)
Service Worker 201 (한국어)Service Worker 201 (한국어)
Service Worker 201 (한국어)Chang W. Doh
 
Classroom 2.0: The Best Places to Learn Online
Classroom 2.0: The Best Places to Learn OnlineClassroom 2.0: The Best Places to Learn Online
Classroom 2.0: The Best Places to Learn OnlineChrystal Porter
 
[1C1]Service Workers
[1C1]Service Workers[1C1]Service Workers
[1C1]Service WorkersNAVER D2
 
WebRTC 전망 최진호_webappscamp
WebRTC 전망 최진호_webappscampWebRTC 전망 최진호_webappscamp
WebRTC 전망 최진호_webappscampBlisson Choi
 
오픈소스와 거버넌스
오픈소스와 거버넌스오픈소스와 거버넌스
오픈소스와 거버넌스Kevin Kim
 
Webrtc 동향과 이슈 2016.08
Webrtc 동향과 이슈 2016.08Webrtc 동향과 이슈 2016.08
Webrtc 동향과 이슈 2016.08sung young son
 
Service Workers for Performance
Service Workers for PerformanceService Workers for Performance
Service Workers for PerformancePatrick Meenan
 
주차정보제공 1020080064179
주차정보제공 1020080064179주차정보제공 1020080064179
주차정보제공 1020080064179Myoung Soo Kang
 
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼병국 민
 
Car as a Service : a booming portfolio of services to expand mobility and dri...
Car as a Service : a booming portfolio of services to expand mobility and dri...Car as a Service : a booming portfolio of services to expand mobility and dri...
Car as a Service : a booming portfolio of services to expand mobility and dri...INOV360
 
Global- Simmatec Automatic Car Parking Systems
Global- Simmatec Automatic Car Parking Systems Global- Simmatec Automatic Car Parking Systems
Global- Simmatec Automatic Car Parking Systems rarkrishnan
 
주차서비스디자인
주차서비스디자인주차서비스디자인
주차서비스디자인Yeaji_kim
 
새로운 패러다임의 UX를 이해하라
새로운 패러다임의 UX를 이해하라새로운 패러다임의 UX를 이해하라
새로운 패러다임의 UX를 이해하라Billy Choi
 
OpenCV를 활용한 컬러추적 문자 인식기의 구현
OpenCV를 활용한 컬러추적 문자 인식기의 구현OpenCV를 활용한 컬러추적 문자 인식기의 구현
OpenCV를 활용한 컬러추적 문자 인식기의 구현Daegi Kim
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises우영 주
 
인펙비전 영상인식 종합주차 관리시스템(2)
인펙비전 영상인식 종합주차 관리시스템(2)인펙비전 영상인식 종합주차 관리시스템(2)
인펙비전 영상인식 종합주차 관리시스템(2)guest2d7179e
 
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)University of Ulsan
 

Viewers also liked (20)

HyWAI Web Bluetooth API
HyWAI Web Bluetooth APIHyWAI Web Bluetooth API
HyWAI Web Bluetooth API
 
Service Worker 101 (한국어)
Service Worker 101 (한국어)Service Worker 101 (한국어)
Service Worker 101 (한국어)
 
Service Worker 201 (한국어)
Service Worker 201 (한국어)Service Worker 201 (한국어)
Service Worker 201 (한국어)
 
Classroom 2.0: The Best Places to Learn Online
Classroom 2.0: The Best Places to Learn OnlineClassroom 2.0: The Best Places to Learn Online
Classroom 2.0: The Best Places to Learn Online
 
[1C1]Service Workers
[1C1]Service Workers[1C1]Service Workers
[1C1]Service Workers
 
WebRTC 전망 최진호_webappscamp
WebRTC 전망 최진호_webappscampWebRTC 전망 최진호_webappscamp
WebRTC 전망 최진호_webappscamp
 
오픈소스와 거버넌스
오픈소스와 거버넌스오픈소스와 거버넌스
오픈소스와 거버넌스
 
Webrtc 동향과 이슈 2016.08
Webrtc 동향과 이슈 2016.08Webrtc 동향과 이슈 2016.08
Webrtc 동향과 이슈 2016.08
 
Service Workers for Performance
Service Workers for PerformanceService Workers for Performance
Service Workers for Performance
 
주차정보제공 1020080064179
주차정보제공 1020080064179주차정보제공 1020080064179
주차정보제공 1020080064179
 
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼
[2008] 숭실대컴퓨터학부 외부세미나 민병국 - Daum검색 튜토리얼
 
Car as a Service : a booming portfolio of services to expand mobility and dri...
Car as a Service : a booming portfolio of services to expand mobility and dri...Car as a Service : a booming portfolio of services to expand mobility and dri...
Car as a Service : a booming portfolio of services to expand mobility and dri...
 
Global- Simmatec Automatic Car Parking Systems
Global- Simmatec Automatic Car Parking Systems Global- Simmatec Automatic Car Parking Systems
Global- Simmatec Automatic Car Parking Systems
 
주차서비스디자인
주차서비스디자인주차서비스디자인
주차서비스디자인
 
새로운 패러다임의 UX를 이해하라
새로운 패러다임의 UX를 이해하라새로운 패러다임의 UX를 이해하라
새로운 패러다임의 UX를 이해하라
 
OpenCV를 활용한 컬러추적 문자 인식기의 구현
OpenCV를 활용한 컬러추적 문자 인식기의 구현OpenCV를 활용한 컬러추적 문자 인식기의 구현
OpenCV를 활용한 컬러추적 문자 인식기의 구현
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
홀로그램
홀로그램홀로그램
홀로그램
 
인펙비전 영상인식 종합주차 관리시스템(2)
인펙비전 영상인식 종합주차 관리시스템(2)인펙비전 영상인식 종합주차 관리시스템(2)
인펙비전 영상인식 종합주차 관리시스템(2)
 
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)
04. IT서비스산업 전문가 특강 (테라데이터 장동인 부사장)
 

Similar to Service workers 기초 및 활용 (Korean)

AngularJS In Production
AngularJS In ProductionAngularJS In Production
AngularJS In ProductionMooYeol Lee
 
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable FunctionsJongin Lee
 
Data-binding AngularJS
Data-binding AngularJSData-binding AngularJS
Data-binding AngularJSEunYoung Kim
 
Node.js 시작하기
Node.js 시작하기Node.js 시작하기
Node.js 시작하기Huey Park
 
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례  그리고, real-time 어플리케이션 개발하기NODE.JS 글로벌 기업 적용 사례  그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기John Kim
 
C++ 개발자와 함께 하는 visual studio 2013
C++ 개발자와 함께 하는 visual studio 2013C++ 개발자와 함께 하는 visual studio 2013
C++ 개발자와 함께 하는 visual studio 2013명신 김
 
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE  [제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE 흥래 김
 
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)Wonseok Jang
 
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기Youngjae Kim
 
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부Joget Workflow
 
Node.js의 도입과 활용
Node.js의 도입과 활용Node.js의 도입과 활용
Node.js의 도입과 활용Jin wook
 
PWA (Progressive Web Apps)
PWA (Progressive Web Apps)PWA (Progressive Web Apps)
PWA (Progressive Web Apps)유 성민
 
도구를 활용한 더 나은 웹 개발: Yeoman
도구를 활용한 더 나은 웹 개발: Yeoman도구를 활용한 더 나은 웹 개발: Yeoman
도구를 활용한 더 나은 웹 개발: YeomanJae Sung Park
 
vert.x 를 활용한 분산서버 개발하기
vert.x 를 활용한 분산서버 개발하기vert.x 를 활용한 분산서버 개발하기
vert.x 를 활용한 분산서버 개발하기John Kim
 
이승재, 실시간 HTTP 양방향 통신, NDC2012
이승재, 실시간 HTTP 양방향 통신, NDC2012이승재, 실시간 HTTP 양방향 통신, NDC2012
이승재, 실시간 HTTP 양방향 통신, NDC2012devCAT Studio, NEXON
 
원모먼트 Vue js 적용기
원모먼트 Vue js 적용기원모먼트 Vue js 적용기
원모먼트 Vue js 적용기우현 김
 
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기현철 조
 
[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridappNAVER D2
 

Similar to Service workers 기초 및 활용 (Korean) (20)

AngularJS In Production
AngularJS In ProductionAngularJS In Production
AngularJS In Production
 
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions
코드로 바로 해버리는 서버리스 오케스트레이션 - Azure Durable Functions
 
Data-binding AngularJS
Data-binding AngularJSData-binding AngularJS
Data-binding AngularJS
 
Node.js 시작하기
Node.js 시작하기Node.js 시작하기
Node.js 시작하기
 
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례  그리고, real-time 어플리케이션 개발하기NODE.JS 글로벌 기업 적용 사례  그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
 
C++ 개발자와 함께 하는 visual studio 2013
C++ 개발자와 함께 하는 visual studio 2013C++ 개발자와 함께 하는 visual studio 2013
C++ 개발자와 함께 하는 visual studio 2013
 
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE  [제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE
[제14회 JCO 컨퍼런스] 개발자를 위한 서버이중화 by JAVACAFE
 
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
 
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기
[Azure bootcamp2017] Azure App Service로 서비스 탄탄하게 관리하기
 
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부
Joget Workflow 오픈 소스 워크플로우 애플리케이션 빌더 - 도입부
 
Node.js의 도입과 활용
Node.js의 도입과 활용Node.js의 도입과 활용
Node.js의 도입과 활용
 
PWA (Progressive Web Apps)
PWA (Progressive Web Apps)PWA (Progressive Web Apps)
PWA (Progressive Web Apps)
 
okspring3x
okspring3xokspring3x
okspring3x
 
도구를 활용한 더 나은 웹 개발: Yeoman
도구를 활용한 더 나은 웹 개발: Yeoman도구를 활용한 더 나은 웹 개발: Yeoman
도구를 활용한 더 나은 웹 개발: Yeoman
 
vert.x 를 활용한 분산서버 개발하기
vert.x 를 활용한 분산서버 개발하기vert.x 를 활용한 분산서버 개발하기
vert.x 를 활용한 분산서버 개발하기
 
이승재, 실시간 HTTP 양방향 통신, NDC2012
이승재, 실시간 HTTP 양방향 통신, NDC2012이승재, 실시간 HTTP 양방향 통신, NDC2012
이승재, 실시간 HTTP 양방향 통신, NDC2012
 
원모먼트 Vue js 적용기
원모먼트 Vue js 적용기원모먼트 Vue js 적용기
원모먼트 Vue js 적용기
 
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
 
[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp
 
Node.js 첫걸음
Node.js 첫걸음Node.js 첫걸음
Node.js 첫걸음
 

More from jungkees

PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Workerjungkees
 
Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bitsjungkees
 
Samsung Internet 4.0
Samsung Internet 4.0Samsung Internet 4.0
Samsung Internet 4.0jungkees
 
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015jungkees
 
Service workers
Service workersService workers
Service workersjungkees
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?jungkees
 
Progress Events Web Apps F2F at San Jose
Progress Events Web Apps F2F at San JoseProgress Events Web Apps F2F at San Jose
Progress Events Web Apps F2F at San Josejungkees
 
XHR Web APps F2F at San Jose
XHR Web APps F2F at San JoseXHR Web APps F2F at San Jose
XHR Web APps F2F at San Josejungkees
 

More from jungkees (8)

PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Worker
 
Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bits
 
Samsung Internet 4.0
Samsung Internet 4.0Samsung Internet 4.0
Samsung Internet 4.0
 
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015
Service Worker at W3C HTML5 Conference in Seoul on the 9th of Dec 2015
 
Service workers
Service workersService workers
Service workers
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?
 
Progress Events Web Apps F2F at San Jose
Progress Events Web Apps F2F at San JoseProgress Events Web Apps F2F at San Jose
Progress Events Web Apps F2F at San Jose
 
XHR Web APps F2F at San Jose
XHR Web APps F2F at San JoseXHR Web APps F2F at San Jose
XHR Web APps F2F at San Jose
 

Service workers 기초 및 활용 (Korean)

  • 2. Jungkee Song Github: https://github.com/jungkees Twitter: @jungkees Google+: +JungkeeSong Facebook: https://www.facebook.com/jungkees
  • 3. Service Worker 가 해결하는 문제들 • 웹의 오프라인 사용성 - 오프라인 우선 (Offline-first) - 개발자가 원하는대로! 개발자가 프로그래밍을 통하여 컨트롤 하는 Cache 개발자가 직접 작성하는 HTTP request 프록시 • 백그라운드 프로세싱 - 브라우저가 실행 중이지 않을 때도 이벤트 처리를 하고 싶다! - Push notification, System alarm, BackgroundSync …
  • 4. 표준개발 현황 W3C Working Draft [ED] https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html [Github] https://github.com/slightlyoff/ServiceWorker
  • 5. 이벤트 기반으로 동작하는 Worker Service Worker는 브라우저에 의해 언제든지 종료 될 수 있음 fetch event Navigation/Resource request onfetch Page SW Cache self.caches.match(url) Promise<response> e.respondWith (Promise<response>) Page Page Navigation/Resource request fetch event e.respondWith (Promise<response>)
  • 6. 개발자가 프로그래밍으로 컨트롤 하는 Cache Cache / CacheStorage 오프젝트 활용 Cache 오브젝트 메소드 참조 caches.open(“myCache”).then(function(cache) { … })
  • 7. 설계 및 동작 원리 • Same origin 기반으로 동작 • URL scope 이 registration 을 식별하는 key가 됨 • Client request 시 matching 되는 SW 에 의해 control 시작 됨 • Registration 은 installing / waiting / active worker를 가짐 • Lifecycle 이벤트: install, activate • Functional 이벤트: fetch, push, sync 등 • Document 또는 Worker 가 Client 가 됨 • Client 가 register 를 요청하여 브라우저에 install 됨 • Resource request 시 선택된 SW 에 의해 control 됨 • HTTPS 필수
  • 8. Client request Client 가 client request 시 SW registration 을 선택함 onfetch sw.js Cache self.caches.match(url) Promise<response> e.respondWith (Promise<response>) “/” /sw.js [ Registration map ] Scope Script URL “/foo/” /foo/sw.js Page Navigate to https://example.com/index.html fetch event Scope matching Run SW
  • 9. Resource request Control 되고 있는 client 는 resource request 시 해당 SW를 사용함 onfetch sw.js Cache self.caches.match(url) Promise<response> e.respondWith (Promise<response>) “/” /sw.js [ Registration map ] Scope Script URL “/foo/” /foo/sw.js Page Fetch “https://example.com/img/flower.png fetch event Control Run SW
  • 10. Registration Client 에서 수행 // scope 은 default로 script의 위치와 동일한 url로 설정 됨 navigator.serviceWorker.register("/assets/v1/serviceworker.js").then( function(registration) { console.log("success!"); registration.installing.postMessage(“Howdy from your installing page."); }, function(why) { console.error("Installing the worker failed!", why); }); “/assets/v1/” /assets/v1/serviceworker.js [ Registration map ] Scope Script URL
  • 11. Registration Client 에서 수행 [ Registration map ] Scope Script URL navigator.serviceWorker.register(“/sw.js”, { scope: “/bar/” }); “/bar/” /sw.js “/foo/” /foo/sw.js “/bar/” /bar/sw.js navigator.serviceWorker.register("/foo/sw.js", { scope: “/foo/” }); navigator.serviceWorker.register("/bar/sw.js");
  • 12. Service Worker 상태 변화 Service Worker 생명주기 HTML5 Rocks Introduction to Service Worker 내용 중 서비스워커 생명주기 단락을 참조해 보자
  • 13. Install 과정: oninstall / onactivate • 브라우저가 SW에 install 이벤트를 발생 시켜줌 - 개발자가 App에 필요한 resource를 미리 Caching할 수 있는 시간 • Event handler 안에서 event.waitUntil(promise) 를 활용하 여 promise를 통해 추상화 된 해당 동작이 resolve될 때까지 SW의 lifetime을 늘일 수 있음 • 브라우저가 SW에 activate 이벤트를 발생 시켜줌 - 개발자가 갱신이 필요한 resource를 정리할 수 있는 시간
  • 14. oninstall SW script fetch및 실행이 성공적으로 이루어 지면 install 이벤트가 service worker 에 dispatch 됨 Jake Archibald’s “The offline cookbook” 중 1-1/1-2 On install 참조
  • 15. onactivate waiting worker 가 activation 될 조건이 만족될 때 activate 이벤트가 service worker 에 dispatch 됨 Jake Archibald’s “The offline cookbook” 중 1-3. On activate 참조
  • 16. Fetch 이벤트 핸들링: onfetch Client / resource request 발생시 마다 fetch 이벤트 가 Service Worker 에 dispatch 됨 Jake Archibald’s “The offline cookbook” 중 1-6. Stale-while-revalidate 참조
  • 17. Service Worker Update 발생 경로 • navigator.serviceWorker.register() API 명시적 호출 • 브라우저에 의한 자동 Update • 매 client request 처리 시 • register.update() API의 명시적 호출
  • 18. Update 동작 모든 client가 unload 되기 전에는 기존 active worker를 그대로 사용 onfetch sw-v2 Cache self.caches.match(url) Promise<response> e.respondWith (Promise<response>) “/” /sw-v1 [ Registration map ] Scope active fetch event - waiting Page sw-v1 Update Install Page sw-v1 /sw-v2 /sw-v2- Page sw-v2 Fetch “https://example.com/img/flower.png Run SW
  • 19. 브라우저 지원 현황 Chrome 40+ Firefox nightly Under consideration 40에서는 Cache, Client 지원하지 않음 IE Partial under flag about:config > dom.serviceWorkers.enabled Jake’s “Is ServiceWorker ready?” Stay alerted! Cache polyfill 활용 가능
  • 20. 참고자료 Service Worker - first draft published - Jake Archibald Specification Github’s explainer Github’s implementation considerations Introduction to Service Worker - Matt Gaunt (번역: 도창욱) The offline cookbook - Jake Archibald Push Notifications & Service Worker