SlideShare a Scribd company logo
WEB WORKERS
JAVASCRIPT MULTITHREADING
Nitin Giri
Current scenario
▶ JavaScript code runs in the same thread as the UI.
▶ JavaScript is a single-threaded technology. Only one thing can be
done at a time.
▶ This is fine at first, but when JavaScript is doing any heavy-lifting, it
can lock up the browser. Locking up the browser is bad, very bad.
What are Web Workers
▶ API for running scripts in the background
▶ Independently of any user interface scripts
▶ Workers are separate JavaScript processes running in separate
threads
▶ Workers execute concurrently
▶ Workers don’t block the UI
▶ Workers allow you to extract up to the last drop of juice from a multicore
CPU
▶ Workers can be dedicated (single tab) or shared among tabs/windows
…
▶ Might be partially replaced by Window.setTimeout() function
▶ If we call function by setTimeout, the execution of script and UI are suspended
▶ When we call function in worker, it doesn’t affect UI and execution flow in any way.
▶ To create Worker, we put JavaScript in separate file and create new Worker
instance:
▶ var worker = new Worker(‘extra_work.js’);
▶ We can communicate with worker using postMessage function and onmessage
listener.
Messages are send to all threads in our application:
MAIN.JS:
extra_work.js
:
var worker = new Worker(‘extra_work.js');
worker.onmessage = function (event) { alert(event.data); };
//do some work; when done post message.
// some_data could be string, array, object etc.
postMessage(some_data);
Limitations:
▶ No Access:
▶ DOM
▶ Window
▶ Document
▶ Parent
▶ Main App Memory/Object
▶ You Do Have Access To
▶ XHR
▶ Navigator , Location
▶ App cache
▶ Import script
Can be used for :-
▶ Background number crunching
▶ Background notification from server to local database
▶ Background updating from server
▶ Search queries
▶ Prefetching data for later use
▶ Process large arrays or JSON responses
Browser Support :-
▶ Chrome 4.0+
▶ Firefox 3.5+
▶ Safari 4.0+
▶ Opera 10.6+
▶ IE 10+

More Related Content

What's hot

Export pdf with puppeteer
Export pdf with puppeteerExport pdf with puppeteer
Export pdf with puppeteer
Knoldus Inc.
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
valuebound
 
Forseti driven javascript
Forseti driven javascriptForseti driven javascript
Forseti driven javascript
Pavneet Singh Saund
 
Phantom js quick start
Phantom js quick startPhantom js quick start
Phantom js quick start
ji guang
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
Gergely Németh
 
Web Workers
Web WorkersWeb Workers
Web Workers
IntexSoft
 
Transakcyjność w django
Transakcyjność w djangoTransakcyjność w django
Transakcyjność w django
Marcin Baran
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
Hengki Sihombing
 
Native code on ms azure platform
Native code on ms azure platformNative code on ms azure platform
Native code on ms azure platform
Slava Lysunkin
 
jQuery (intermediate)
jQuery (intermediate)jQuery (intermediate)
jQuery (intermediate)
Madhukar Anand
 
NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1
Tomislav Capan
 
Full Stack 2019 edition
Full Stack 2019 editionFull Stack 2019 edition
Full Stack 2019 edition
Matjaž Lipuš
 
GruntJS + Wordpress
GruntJS + WordpressGruntJS + Wordpress
GruntJS + Wordpress
Leonardo Balter
 
Full stack java script development
Full stack java script developmentFull stack java script development
Full stack java script development
Tomislav Capan
 
Introduction to webGL
Introduction to webGLIntroduction to webGL
Introduction to webGL
志鴻 詹
 
Introduction To JavaScript Ajax
Introduction To JavaScript AjaxIntroduction To JavaScript Ajax
Introduction To JavaScript Ajax
Reema
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and PatternsFRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
Leapfrog Technology Inc.
 
Nightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador MolinaNightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador Molina
Salvador Molina (Slv_)
 
Simple Singleton Java
Simple Singleton JavaSimple Singleton Java
Simple Singleton Java
Christian Hipolito
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js Minitalk
Philipp Naderer
 

What's hot (20)

Export pdf with puppeteer
Export pdf with puppeteerExport pdf with puppeteer
Export pdf with puppeteer
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
 
Forseti driven javascript
Forseti driven javascriptForseti driven javascript
Forseti driven javascript
 
Phantom js quick start
Phantom js quick startPhantom js quick start
Phantom js quick start
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Web Workers
Web WorkersWeb Workers
Web Workers
 
Transakcyjność w django
Transakcyjność w djangoTransakcyjność w django
Transakcyjność w django
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
 
Native code on ms azure platform
Native code on ms azure platformNative code on ms azure platform
Native code on ms azure platform
 
jQuery (intermediate)
jQuery (intermediate)jQuery (intermediate)
jQuery (intermediate)
 
NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1
 
Full Stack 2019 edition
Full Stack 2019 editionFull Stack 2019 edition
Full Stack 2019 edition
 
GruntJS + Wordpress
GruntJS + WordpressGruntJS + Wordpress
GruntJS + Wordpress
 
Full stack java script development
Full stack java script developmentFull stack java script development
Full stack java script development
 
Introduction to webGL
Introduction to webGLIntroduction to webGL
Introduction to webGL
 
Introduction To JavaScript Ajax
Introduction To JavaScript AjaxIntroduction To JavaScript Ajax
Introduction To JavaScript Ajax
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and PatternsFRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
 
Nightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador MolinaNightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador Molina
 
Simple Singleton Java
Simple Singleton JavaSimple Singleton Java
Simple Singleton Java
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js Minitalk
 

Viewers also liked

Semi 2 estadística maría
Semi 2 estadística maríaSemi 2 estadística maría
Semi 2 estadística maría
margilcru
 
Deutsche EuroShop: Acquisition Details Olympia Center Brno
Deutsche EuroShop: Acquisition Details Olympia Center BrnoDeutsche EuroShop: Acquisition Details Olympia Center Brno
Deutsche EuroShop: Acquisition Details Olympia Center Brno
Deutsche EuroShop AG
 
Advertising Comparision- TBZ & Tanishquie
Advertising Comparision- TBZ & TanishquieAdvertising Comparision- TBZ & Tanishquie
Advertising Comparision- TBZ & Tanishquie
sdusane1
 
Steam trading cards - Gamification in customer engagement - Manu Melwin Joy
Steam trading cards - Gamification in customer engagement  - Manu Melwin JoySteam trading cards - Gamification in customer engagement  - Manu Melwin Joy
Steam trading cards - Gamification in customer engagement - Manu Melwin Joy
manumelwin
 
Образование взрослых в свете идей целостного развития человека
Образование взрослых в свете идей целостного развития человекаОбразование взрослых в свете идей целостного развития человека
Образование взрослых в свете идей целостного развития человека
Библиотека Московского Педагогического Государственного Университета
 
Consonants
ConsonantsConsonants
Consonants
dien96
 
2B
2B2B
Idi2017 - Cloud DB: strengths and weaknesses
Idi2017 - Cloud DB: strengths and weaknessesIdi2017 - Cloud DB: strengths and weaknesses
Idi2017 - Cloud DB: strengths and weaknesses
Linuxaria.com
 

Viewers also liked (8)

Semi 2 estadística maría
Semi 2 estadística maríaSemi 2 estadística maría
Semi 2 estadística maría
 
Deutsche EuroShop: Acquisition Details Olympia Center Brno
Deutsche EuroShop: Acquisition Details Olympia Center BrnoDeutsche EuroShop: Acquisition Details Olympia Center Brno
Deutsche EuroShop: Acquisition Details Olympia Center Brno
 
Advertising Comparision- TBZ & Tanishquie
Advertising Comparision- TBZ & TanishquieAdvertising Comparision- TBZ & Tanishquie
Advertising Comparision- TBZ & Tanishquie
 
Steam trading cards - Gamification in customer engagement - Manu Melwin Joy
Steam trading cards - Gamification in customer engagement  - Manu Melwin JoySteam trading cards - Gamification in customer engagement  - Manu Melwin Joy
Steam trading cards - Gamification in customer engagement - Manu Melwin Joy
 
Образование взрослых в свете идей целостного развития человека
Образование взрослых в свете идей целостного развития человекаОбразование взрослых в свете идей целостного развития человека
Образование взрослых в свете идей целостного развития человека
 
Consonants
ConsonantsConsonants
Consonants
 
2B
2B2B
2B
 
Idi2017 - Cloud DB: strengths and weaknesses
Idi2017 - Cloud DB: strengths and weaknessesIdi2017 - Cloud DB: strengths and weaknesses
Idi2017 - Cloud DB: strengths and weaknesses
 

Similar to Web worker

GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
Gbolahan Alli
 
webworkers
webworkerswebworkers
webworkers
Asanka Indrajith
 
Developing advanced universal apps using html & js
Developing advanced universal apps using html & jsDeveloping advanced universal apps using html & js
Developing advanced universal apps using html & js
Senthamil Selvan
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
Adrian Caetano
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
Andrew Rota
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer
JooinK
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sample
prahalad_das_in
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
Dicoding
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
TO THE NEW | Technology
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Fwdays
 
Javascript why what and how
Javascript why what and howJavascript why what and how
Javascript why what and how
sureshpraja1234
 
Service worker API
Service worker APIService worker API
Service worker API
Giorgio Natili
 
Jwis2011 ruo ando
Jwis2011 ruo andoJwis2011 ruo ando
Jwis2011 ruo ando
Ruo Ando
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web worker
Suresh Patidar
 
Ad111
Ad111Ad111
Ad111
ddrschiw
 
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
ddrschiw
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
pjcozzi
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
Luram Archanjo
 
Nodejs
NodejsNodejs
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 

Similar to Web worker (20)

GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
 
webworkers
webworkerswebworkers
webworkers
 
Developing advanced universal apps using html & js
Developing advanced universal apps using html & jsDeveloping advanced universal apps using html & js
Developing advanced universal apps using html & js
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sample
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
 
Javascript why what and how
Javascript why what and howJavascript why what and how
Javascript why what and how
 
Service worker API
Service worker APIService worker API
Service worker API
 
Jwis2011 ruo ando
Jwis2011 ruo andoJwis2011 ruo ando
Jwis2011 ruo ando
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web worker
 
Ad111
Ad111Ad111
Ad111
 
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
 
Nodejs
NodejsNodejs
Nodejs
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

Web worker

  • 2.
  • 3. Current scenario ▶ JavaScript code runs in the same thread as the UI. ▶ JavaScript is a single-threaded technology. Only one thing can be done at a time. ▶ This is fine at first, but when JavaScript is doing any heavy-lifting, it can lock up the browser. Locking up the browser is bad, very bad.
  • 4. What are Web Workers ▶ API for running scripts in the background ▶ Independently of any user interface scripts ▶ Workers are separate JavaScript processes running in separate threads ▶ Workers execute concurrently ▶ Workers don’t block the UI ▶ Workers allow you to extract up to the last drop of juice from a multicore CPU ▶ Workers can be dedicated (single tab) or shared among tabs/windows
  • 5. … ▶ Might be partially replaced by Window.setTimeout() function ▶ If we call function by setTimeout, the execution of script and UI are suspended ▶ When we call function in worker, it doesn’t affect UI and execution flow in any way. ▶ To create Worker, we put JavaScript in separate file and create new Worker instance: ▶ var worker = new Worker(‘extra_work.js’); ▶ We can communicate with worker using postMessage function and onmessage listener.
  • 6.
  • 7. Messages are send to all threads in our application: MAIN.JS: extra_work.js : var worker = new Worker(‘extra_work.js'); worker.onmessage = function (event) { alert(event.data); }; //do some work; when done post message. // some_data could be string, array, object etc. postMessage(some_data);
  • 8. Limitations: ▶ No Access: ▶ DOM ▶ Window ▶ Document ▶ Parent ▶ Main App Memory/Object ▶ You Do Have Access To ▶ XHR ▶ Navigator , Location ▶ App cache ▶ Import script
  • 9. Can be used for :- ▶ Background number crunching ▶ Background notification from server to local database ▶ Background updating from server ▶ Search queries ▶ Prefetching data for later use ▶ Process large arrays or JSON responses
  • 10. Browser Support :- ▶ Chrome 4.0+ ▶ Firefox 3.5+ ▶ Safari 4.0+ ▶ Opera 10.6+ ▶ IE 10+