SlideShare a Scribd company logo
Web Workers
JAGADEESH PATTA( PJ )
Agenda
 Introduction
 Steps to create service worker.
Introduction
 Web workers are scripts that are runs in background threads.
 Web worker thread perform tasks without interfering UI
thread.
 Web workers can perform I/O operations using
XMLHttpRequest.
Introduction(cont…)
 Web workers can communicate with UI thread using event
messages.
Steps to create web worker
 Create web worker file
 Create object for web worker
 Communication with Web Worker
 Terminate web worker
Create web worker file
Step-1:
Check weather the browser supports the web workers or not.
If ( typeof Worker !== “undefined” ) {
// Your browser supports web workers
} else {
// Your browser not supporting web workers.
}
Create web worker file(cont…)
Step-2(web-worker-name.js):
var count = 0;
function getCount(){
count = count + 1;
postMessage(count);
setTimeout(“getCount()”, 1000);
}
getCount();
Create Object for web worker
 Web worker file and current JavaScript code must be comes
under same origin.
 Check existence of web worker object.
If ( typeof workerObj == “undefined” ) {
workerObj = new Worker(“web-worker-name.js”);
}
Communication with Web Worker
 The communication between web worker and UI thread done by
event messages.
 Send / Receive data using postMessage and onmessage
methods.
Step-1(send data from web worker):
postMessage(“content needs to be send”);
Communication(cont…)
Step-2(Receive data from web worker):
workerObj.onmessage = function(event){
var element = document.getElementById(‘id’);
element.innerHTML = event.data;
}
Terminating web worker
 check weather the workerObj is undefined or not.
if ( typeof workerObj !== “undefined” ) {
workerObj.terminate();
}
Questions ?
Thank You

More Related Content

What's hot (16)

PPTX
jQuery basics for Beginners
Pooja Saxena
 
PDF
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
Mukul Jain
 
PDF
Lec 5
maamir farooq
 
PDF
METEOR 101
Tin Aung Lin
 
PPTX
Deceptive simplicity of async and await
Andrei Marukovich
 
PPTX
From zero to hero with the reactive extensions for JavaScript
Maurice De Beijer [MVP]
 
PDF
Inspiring conference - Automation & external service integration
dfeyer
 
PPT
2310 b 05
Krazy Koder
 
PPTX
Scott Guthrie at Dot Net Startup meetup
Marcelo Calbucci
 
PPTX
iOS Beginners Lesson 4
Calvin Cheng
 
PPTX
[SoftServe IT Academy] - JavaScript Events
Ivan Matiishyn
 
PPT
Web Os Hands On
360|Conferences
 
PPTX
Angular Data Binding
Duy Khanh
 
PDF
Reactive Programming in the Browser feat. Scala.js and Rx
Luka Jacobowitz
 
PDF
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
 
PDF
Ember.js for Big Profit
CodeCore
 
jQuery basics for Beginners
Pooja Saxena
 
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
Mukul Jain
 
METEOR 101
Tin Aung Lin
 
Deceptive simplicity of async and await
Andrei Marukovich
 
From zero to hero with the reactive extensions for JavaScript
Maurice De Beijer [MVP]
 
Inspiring conference - Automation & external service integration
dfeyer
 
2310 b 05
Krazy Koder
 
Scott Guthrie at Dot Net Startup meetup
Marcelo Calbucci
 
iOS Beginners Lesson 4
Calvin Cheng
 
[SoftServe IT Academy] - JavaScript Events
Ivan Matiishyn
 
Web Os Hands On
360|Conferences
 
Angular Data Binding
Duy Khanh
 
Reactive Programming in the Browser feat. Scala.js and Rx
Luka Jacobowitz
 
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
 
Ember.js for Big Profit
CodeCore
 

Similar to Web workers | JavaScript | HTML API (20)

PDF
Beyond HTML: Tools for Building Web 2.0 Apps
Marcos Caceres
 
PPTX
webworkers
Asanka Indrajith
 
PDF
JavaScript Web Workers
Tobias Pfeiffer
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PPT
Responsive interfaces
Nicholas Zakas
 
PDF
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
PPT
JavaScript Libraries
Daminda Herath
 
PDF
1 ppt-ajax with-j_query
Fajar Baskoro
 
PPT
Asp
yuvaraj72
 
PPT
eXo SEA - JavaScript Introduction Training
Hoat Le
 
PPTX
ASP.NET Lecture 1
Julie Iskander
 
PPTX
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
PDF
ajax_pdf
tutorialsruby
 
PDF
ajax_pdf
tutorialsruby
 
PPT
Qtp not just for gui anymore
Pragya Rastogi
 
PPTX
01 Introduction - JavaScript Development
Tommy Vercety
 
PDF
Asp.net By Durgesh Singh
imdurgesh
 
PPTX
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
PDF
Node.js introduction
Parth Joshi
 
PPT
Ajax Lecture Notes
Santhiya Grace
 
Beyond HTML: Tools for Building Web 2.0 Apps
Marcos Caceres
 
webworkers
Asanka Indrajith
 
JavaScript Web Workers
Tobias Pfeiffer
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Responsive interfaces
Nicholas Zakas
 
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
JavaScript Libraries
Daminda Herath
 
1 ppt-ajax with-j_query
Fajar Baskoro
 
eXo SEA - JavaScript Introduction Training
Hoat Le
 
ASP.NET Lecture 1
Julie Iskander
 
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
ajax_pdf
tutorialsruby
 
ajax_pdf
tutorialsruby
 
Qtp not just for gui anymore
Pragya Rastogi
 
01 Introduction - JavaScript Development
Tommy Vercety
 
Asp.net By Durgesh Singh
imdurgesh
 
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
Node.js introduction
Parth Joshi
 
Ajax Lecture Notes
Santhiya Grace
 
Ad

More from pcnmtutorials (18)

PPTX
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
PPTX
11. Iterators | ES6 | JavaScript | TypeScript
pcnmtutorials
 
PDF
10. symbols | ES6 | JavaScript | TypeScript
pcnmtutorials
 
PPTX
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials
 
PPTX
8. Spread Syntax | ES6 | JavaScript
pcnmtutorials
 
PPTX
7. Rest parameters | ES6 | JavaScript
pcnmtutorials
 
PPTX
6. Default parameters | ES6 | JavaScript
pcnmtutorials
 
PPTX
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
PPTX
4. Template strings | ES6
pcnmtutorials
 
PPTX
3. Object literals | ES6 | JSON
pcnmtutorials
 
PPTX
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
pcnmtutorials
 
PPTX
1. Arrow Functions | JavaScript | ES6
pcnmtutorials
 
PPTX
Decorators | TypeScript | Angular2 Decorators
pcnmtutorials
 
PPTX
Declaration merging | Typescript
pcnmtutorials
 
PPTX
Module resolution | Typescript
pcnmtutorials
 
PPTX
Material design in android L developer Preview
pcnmtutorials
 
PPT
data structure, stack, stack data structure
pcnmtutorials
 
PPTX
1.introduction to data_structures
pcnmtutorials
 
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
11. Iterators | ES6 | JavaScript | TypeScript
pcnmtutorials
 
10. symbols | ES6 | JavaScript | TypeScript
pcnmtutorials
 
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials
 
8. Spread Syntax | ES6 | JavaScript
pcnmtutorials
 
7. Rest parameters | ES6 | JavaScript
pcnmtutorials
 
6. Default parameters | ES6 | JavaScript
pcnmtutorials
 
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
4. Template strings | ES6
pcnmtutorials
 
3. Object literals | ES6 | JSON
pcnmtutorials
 
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
pcnmtutorials
 
1. Arrow Functions | JavaScript | ES6
pcnmtutorials
 
Decorators | TypeScript | Angular2 Decorators
pcnmtutorials
 
Declaration merging | Typescript
pcnmtutorials
 
Module resolution | Typescript
pcnmtutorials
 
Material design in android L developer Preview
pcnmtutorials
 
data structure, stack, stack data structure
pcnmtutorials
 
1.introduction to data_structures
pcnmtutorials
 
Ad

Recently uploaded (20)

PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 

Web workers | JavaScript | HTML API

  • 2. Agenda  Introduction  Steps to create service worker.
  • 3. Introduction  Web workers are scripts that are runs in background threads.  Web worker thread perform tasks without interfering UI thread.  Web workers can perform I/O operations using XMLHttpRequest.
  • 4. Introduction(cont…)  Web workers can communicate with UI thread using event messages.
  • 5. Steps to create web worker  Create web worker file  Create object for web worker  Communication with Web Worker  Terminate web worker
  • 6. Create web worker file Step-1: Check weather the browser supports the web workers or not. If ( typeof Worker !== “undefined” ) { // Your browser supports web workers } else { // Your browser not supporting web workers. }
  • 7. Create web worker file(cont…) Step-2(web-worker-name.js): var count = 0; function getCount(){ count = count + 1; postMessage(count); setTimeout(“getCount()”, 1000); } getCount();
  • 8. Create Object for web worker  Web worker file and current JavaScript code must be comes under same origin.  Check existence of web worker object. If ( typeof workerObj == “undefined” ) { workerObj = new Worker(“web-worker-name.js”); }
  • 9. Communication with Web Worker  The communication between web worker and UI thread done by event messages.  Send / Receive data using postMessage and onmessage methods. Step-1(send data from web worker): postMessage(“content needs to be send”);
  • 10. Communication(cont…) Step-2(Receive data from web worker): workerObj.onmessage = function(event){ var element = document.getElementById(‘id’); element.innerHTML = event.data; }
  • 11. Terminating web worker  check weather the workerObj is undefined or not. if ( typeof workerObj !== “undefined” ) { workerObj.terminate(); }