SlideShare ist ein Scribd-Unternehmen logo
1 von 18
HTML5의 Web Worker YonghoJi
Javascript코드를 background에서 실행시키기 위한 기술 Background에서 실행되는 코드를 ‘Worker’라고 불린다. UI(DOM)과는 완전히 분리된 환경에서 동작 ,[object Object],Web Woker란?
Worker를 이용한 병렬 처리 개념 1 출처 : http://dev.opera.com/articles/view/web-workers-rise-up/
Worker를 이용한 병렬 처리 개념 2 DOM UI Thread Worker new UI 변경 postMessage() postMessage() Worker로 DOM을 조작할 수 없음 메시지를 통해 데이터를 주고 받음
DOM 조작 불가능 (it’s not thread-safe) Window object 조작 불가능 Document object 조작 불가능 Parent object 조작 불가능 Page의 script, functions, globals조작 불가능 postMessage() 제외 Web Worker 제약
Object, Array, Date, Math, String 등의 Javascript객체 사용 navigator object location object(read only) setTimeout()/clearTimeout()/setInterval()/clearInternal() XMLHttpRequest Application Cache http://www.html5rocks.com/tutorials/appcache/beginner/ importScripts() 를 이용하면 외부 script 임포트(같은 도메인에 있는 script files만 가능) Web Worker에서 사용 가능한 것
긴 시간이 걸리는 스크립트 매우 복잡한 수학적 계산작업 원격지에 있는 소스에 대한 Access 작업 (WebSocket) 로컬 스토리지 Access 작업 Background에서 조용히 오랜시간 해야하는 작업 UI Thread에 방해 없이 지속적으로 수행해야하는 작업 Web Worker 활용
//Web Worker를 지원하는가 체크  function getWebWorkerSupport() {    return (typeof(Worker) !== "undefined") ? true : false; } if (getWebWorkerSupport() ) {     alert(“이 브라우져는 Web Worker를 지원합니다”); } else {     alert(“이 브라우져는 Web Worker를 지원안해요!”); } Web Worker 지원 브라우저 체크
Web Worker 지원 브라우져(2011.05) 출처 : caniuse.com 참고 : 아이폰 사파리는 지원 안함
어떤 Javascript파일이든 Worker가 될 수 있다. Web Worker 사용법 1 그림출처 : http://wearehugh.com/public/2010/08/html5-web-workers/
Message로 Worker와 함께 통신할 수 있다. Web Worker 사용법 2
반대로 Worker가 Message를 보낼 수도 있다. Web Worker 사용법 3
postMessage()의 인자는 어떤 type이든 상관없다. 이 인자는 JSON으로 직렬화 처리 된다. Web Woker사용법 4
http://jidolstar.net/study/html5/webworker/worker1.html Worker 예제소스 및 실행
Worker Worker 객체와 백그라운드 프로세스가 일대일로 대응하는 간단한 모델 var worker = new Worker(‘worker.js’); SharedWorker 여러개의 Worker 객체가 하나의 백그라운드 프로세스를 공유하는 모델 var worker1 = new SharedWorker(‘worker.js’, ‘wk’); var worker2 = new SharedWorker(‘worker.js’, ‘wk’); SharedWorker에 대해
http://jidolstar.net/study/html5/webworker/sharedworker.html SharedWorker예제소스 및 실행
Web Worker Specification http://www.whatwg.org/specs/web-workers/current-work/ The Basics of Web Workers http://www.html5rocks.com/tutorials/workers/basics/  Using web worker http://developer.mozilla.org/en/Using_web_workers Web Worker rise up! http://dev.opera.com/articles/view/web-workers-rise-up/ HTML5 Web Workers http://www.tutorialspoint.com/html5/html5_web_workers.htm (동영상)HTML5 Web Sockets, Web Workers and Geolocation Unleashed http://video.disruptivecode.com/video/840617/html5-web-sockets-web-workers References
Juliamap http://juliamap.googlelabs.com Motion Tracker http://htmlfive.appspot.com/static/tracker1.html Simulated Annealing  http://people.mozilla.com/~prouget/demos/worker_and_simulatedannealing/index.xhtml GeoJSON/WebWorker Example http://dev.openlayers.org/sandbox/camptocamp/canvas/openlayers/examples/geojson-webworker.html Examples

Weitere ähnliche Inhalte

Was ist angesagt?

Soutenance de stage messerlin
Soutenance de stage messerlinSoutenance de stage messerlin
Soutenance de stage messerlin
Gaut' Xp
 

Was ist angesagt? (20)

Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
Php ppt
Php pptPhp ppt
Php ppt
 
Soutenance de stage messerlin
Soutenance de stage messerlinSoutenance de stage messerlin
Soutenance de stage messerlin
 
C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features Summary
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
CV youssef mami Analyste développeur formateur expert en sécurité informatiq...
CV youssef mami Analyste développeur formateur expert  en sécurité informatiq...CV youssef mami Analyste développeur formateur expert  en sécurité informatiq...
CV youssef mami Analyste développeur formateur expert en sécurité informatiq...
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Introduction to webassembly
Introduction to webassemblyIntroduction to webassembly
Introduction to webassembly
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: Introduction
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
Java
JavaJava
Java
 
Node.js
Node.jsNode.js
Node.js
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
 
[H3 2012] 오픈소스로 개발 실력 쌓기
[H3 2012] 오픈소스로 개발 실력 쌓기[H3 2012] 오픈소스로 개발 실력 쌓기
[H3 2012] 오픈소스로 개발 실력 쌓기
 

Ähnlich wie HTML5의 web worker

JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
sys4u
 
Memory_leak_patterns_in_JavaScript_SYS4U
Memory_leak_patterns_in_JavaScript_SYS4UMemory_leak_patterns_in_JavaScript_SYS4U
Memory_leak_patterns_in_JavaScript_SYS4U
sys4u
 
Introduction to Fork Join Framework_SYS4U I&C
Introduction to Fork Join Framework_SYS4U I&CIntroduction to Fork Join Framework_SYS4U I&C
Introduction to Fork Join Framework_SYS4U I&C
sys4u
 

Ähnlich wie HTML5의 web worker (20)

JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
JQuery를 이용하여 웹 위젯 작성하기_(주)시스포유아이앤씨
 
Web workers
Web workersWeb workers
Web workers
 
Html5 web workers
Html5 web workersHtml5 web workers
Html5 web workers
 
Facebook은 React를 왜 만들었을까?
Facebook은 React를 왜 만들었을까? Facebook은 React를 왜 만들었을까?
Facebook은 React를 왜 만들었을까?
 
Data-binding AngularJS
Data-binding AngularJSData-binding AngularJS
Data-binding AngularJS
 
[NEXT] Android 개발 경험 프로젝트 4일차 (Networking)
[NEXT] Android 개발 경험 프로젝트 4일차 (Networking)[NEXT] Android 개발 경험 프로젝트 4일차 (Networking)
[NEXT] Android 개발 경험 프로젝트 4일차 (Networking)
 
Memory_leak_patterns_in_JavaScript_SYS4U
Memory_leak_patterns_in_JavaScript_SYS4UMemory_leak_patterns_in_JavaScript_SYS4U
Memory_leak_patterns_in_JavaScript_SYS4U
 
RequireJS를 이용한 모듈관리.
RequireJS를 이용한 모듈관리.RequireJS를 이용한 모듈관리.
RequireJS를 이용한 모듈관리.
 
4-3. jquery
4-3. jquery4-3. jquery
4-3. jquery
 
[D2 CAMPUS] 안드로이드 오픈소스 스터디자료 - Http Request
[D2 CAMPUS] 안드로이드 오픈소스 스터디자료 - Http Request[D2 CAMPUS] 안드로이드 오픈소스 스터디자료 - Http Request
[D2 CAMPUS] 안드로이드 오픈소스 스터디자료 - Http Request
 
Introduction to Fork Join Framework_SYS4U I&C
Introduction to Fork Join Framework_SYS4U I&CIntroduction to Fork Join Framework_SYS4U I&C
Introduction to Fork Join Framework_SYS4U I&C
 
LucideWorks Banana 소개
LucideWorks Banana 소개 LucideWorks Banana 소개
LucideWorks Banana 소개
 
Front end dev 2016 & beyond
Front end dev 2016 & beyondFront end dev 2016 & beyond
Front end dev 2016 & beyond
 
4-2. ajax
4-2. ajax4-2. ajax
4-2. ajax
 
Node.js의 도입과 활용
Node.js의 도입과 활용Node.js의 도입과 활용
Node.js의 도입과 활용
 
파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 파이썬 플라스크 이해하기
파이썬 플라스크 이해하기
 
[W3C HTML5 2017] 예제를 통해 쉽게 살펴보는 Vue.js
[W3C HTML5 2017] 예제를 통해 쉽게 살펴보는 Vue.js [W3C HTML5 2017] 예제를 통해 쉽게 살펴보는 Vue.js
[W3C HTML5 2017] 예제를 통해 쉽게 살펴보는 Vue.js
 
CRUD Pattern in Ajax
CRUD Pattern in AjaxCRUD Pattern in Ajax
CRUD Pattern in Ajax
 
Node.js 시작하기
Node.js 시작하기Node.js 시작하기
Node.js 시작하기
 
예제를 통해 쉽게_살펴보는_뷰제이에스
예제를 통해 쉽게_살펴보는_뷰제이에스예제를 통해 쉽게_살펴보는_뷰제이에스
예제를 통해 쉽게_살펴보는_뷰제이에스
 

HTML5의 web worker

  • 2.
  • 3. Worker를 이용한 병렬 처리 개념 1 출처 : http://dev.opera.com/articles/view/web-workers-rise-up/
  • 4. Worker를 이용한 병렬 처리 개념 2 DOM UI Thread Worker new UI 변경 postMessage() postMessage() Worker로 DOM을 조작할 수 없음 메시지를 통해 데이터를 주고 받음
  • 5. DOM 조작 불가능 (it’s not thread-safe) Window object 조작 불가능 Document object 조작 불가능 Parent object 조작 불가능 Page의 script, functions, globals조작 불가능 postMessage() 제외 Web Worker 제약
  • 6. Object, Array, Date, Math, String 등의 Javascript객체 사용 navigator object location object(read only) setTimeout()/clearTimeout()/setInterval()/clearInternal() XMLHttpRequest Application Cache http://www.html5rocks.com/tutorials/appcache/beginner/ importScripts() 를 이용하면 외부 script 임포트(같은 도메인에 있는 script files만 가능) Web Worker에서 사용 가능한 것
  • 7. 긴 시간이 걸리는 스크립트 매우 복잡한 수학적 계산작업 원격지에 있는 소스에 대한 Access 작업 (WebSocket) 로컬 스토리지 Access 작업 Background에서 조용히 오랜시간 해야하는 작업 UI Thread에 방해 없이 지속적으로 수행해야하는 작업 Web Worker 활용
  • 8. //Web Worker를 지원하는가 체크 function getWebWorkerSupport() { return (typeof(Worker) !== "undefined") ? true : false; } if (getWebWorkerSupport() ) { alert(“이 브라우져는 Web Worker를 지원합니다”); } else { alert(“이 브라우져는 Web Worker를 지원안해요!”); } Web Worker 지원 브라우저 체크
  • 9. Web Worker 지원 브라우져(2011.05) 출처 : caniuse.com 참고 : 아이폰 사파리는 지원 안함
  • 10. 어떤 Javascript파일이든 Worker가 될 수 있다. Web Worker 사용법 1 그림출처 : http://wearehugh.com/public/2010/08/html5-web-workers/
  • 11. Message로 Worker와 함께 통신할 수 있다. Web Worker 사용법 2
  • 12. 반대로 Worker가 Message를 보낼 수도 있다. Web Worker 사용법 3
  • 13. postMessage()의 인자는 어떤 type이든 상관없다. 이 인자는 JSON으로 직렬화 처리 된다. Web Woker사용법 4
  • 15. Worker Worker 객체와 백그라운드 프로세스가 일대일로 대응하는 간단한 모델 var worker = new Worker(‘worker.js’); SharedWorker 여러개의 Worker 객체가 하나의 백그라운드 프로세스를 공유하는 모델 var worker1 = new SharedWorker(‘worker.js’, ‘wk’); var worker2 = new SharedWorker(‘worker.js’, ‘wk’); SharedWorker에 대해
  • 17. Web Worker Specification http://www.whatwg.org/specs/web-workers/current-work/ The Basics of Web Workers http://www.html5rocks.com/tutorials/workers/basics/ Using web worker http://developer.mozilla.org/en/Using_web_workers Web Worker rise up! http://dev.opera.com/articles/view/web-workers-rise-up/ HTML5 Web Workers http://www.tutorialspoint.com/html5/html5_web_workers.htm (동영상)HTML5 Web Sockets, Web Workers and Geolocation Unleashed http://video.disruptivecode.com/video/840617/html5-web-sockets-web-workers References
  • 18. Juliamap http://juliamap.googlelabs.com Motion Tracker http://htmlfive.appspot.com/static/tracker1.html Simulated Annealing http://people.mozilla.com/~prouget/demos/worker_and_simulatedannealing/index.xhtml GeoJSON/WebWorker Example http://dev.openlayers.org/sandbox/camptocamp/canvas/openlayers/examples/geojson-webworker.html Examples