SlideShare a Scribd company logo
1 of 22
Download to read offline
HTML5 Web Storage
(DOM storage)




                    ©Inbal Geffen 2012
Why?
●   HTTP is stateless

●   We want to keep record of what the user did

●   We want to be able to work "offline"

●   We don't want to force users to signup / login




                                                     ©Inbal Geffen 2012
Cookies
●   Used before HTML5 Web Storage

●   4KB memory limitation per cookie

●   Sent in every request

●   Have a "bad reputation"




                                       ©Inbal Geffen 2012
localStorage vs.
sessionStorage
In Both
●   Data is stored as key/value pairs

●   Data is stored in string form

●   Use the same API : setItem(), getItem(), clear(), removeItem()

●   Fire 'storage' event




                                                                 ©Inbal Geffen 2012
localStorage vs.
sessionStorage
Differ in scope and lifetime
●   sessionStorage is stored until the window is closed

●   localStorage is stored until the storage is cleared

●   localStorage is synchronized within the browser windows and tabs

●   sessionStorage - multiple instances of the same window without collision




                                                                ©Inbal Geffen 2012
Web Storage Support
●   We must remember that not all browsers support "Web Storage"




function checkStorageSupport() {
        if (!window.localStorage) {
        alert('This browser does NOT support localStorage');
        }
   }




                                                               ©Inbal Geffen 2012
Web Storage API
setItem
//set Item in local storage
localStorage.setItem("userName", userName);

//can also use immediate set, but this is less recommended
localStorage.userName=userName;



//set Item in session storage
sessionStorage.setItem("userName", userName);

//can also use the immediate set, but this is less recommended
sessionStorage.userName=userName;


                                                                 ©Inbal Geffen 2012
Web Storage API
getItem
//get Item in local storage
var userName = localStorage.getItem("userName);

//can also use immediate get, but this is less recommended
var userName = localStorage.userName;



//get Item in session storage
sessionStorage.getItem("userName);

//can also use the immediate set, but this is less recommended
var userName = sessionStorage.userName;


                                                                 ©Inbal Geffen 2012
Web Storage API
clear(), removeItem
//clear the local storage
localStorage.clear();

//remove specific item from local storage
localStorage.removeItem("userName");
//localStorage.getItem("userName") => NULL

//clear the session storage
sessionStorage.clear();

//remove specific item from session storage
sessionStorage.removeItem("userName");



                                              ©Inbal Geffen 2012
Web Storage API

●   Web Storage is an array

●   localStorage.length

●   Item in the ith position in the array : localStorage.key(i)




                                                                  ©Inbal Geffen 2012
Storage Event
//Fired when performing an operation on the storage


if (window.addEventListener) {
    window.addEventListener("storage", handleStorageEvent, false);
} else {
    // for IE versions below IE9
    window.attachEvent("onstorage", handleStorageEvent);
};

function handleStorageEvent(eventData) {
  // Do something
}



                                                                 ©Inbal Geffen 2012
Things to remember
• Local storage persists until it is deleted or the browser’s cache is cleared.

• Session storage persists until it is deleted or the browsing context is closed.

• Data stored by one browser is not accessible by another browser.
  For example, data stored by Chrome is not seen by Firefox.

• Objects should be stored as strings.

• For security reasons, sensitive data should not be stored, especially in local
  storage.

• Changes to a storage area cause a “storage” event to be fired.

• As with many other HTML5 features, web storage is not yet implemented
  consistently.


                                                                       ©Inbal Geffen 2012
HTML5 Web Workers




                    ©Inbal Geffen 2012
THE PROBLEM:
 JAVASCRIPT CONCURRENCY
• JavaScript is a single-threaded environment

• Used to be "solved" with asynchronous techniques such as:
  setTimeout(), setInterval(), XMLHttpRequest, and event handlers

• Asynchronous events are processed after the current executing script

• Web Workers are the HTML5 solution, enabling multi threading




                                                                    ©Inbal Geffen 2012
Web Workers - Use Cases

Doing an action/process on the background, without harming the UI
Show something to the user and then we can update the UI with the result.

●   Updating many rows of local web database

●   Processing large arrays

●   Background I/O - fetch data for later

●   Spell checker

●   Code syntax highlighting or other real-time text formatting




                                                                     ©Inbal Geffen 2012
Web Workers Support
●   We need to remember to check browser support for web workers

function checkWorkerSupport() {
         if (typeof(window.Worker) === "undefined")
         alert("Your browser doesn't support HTML5 Web Workers!");
    }




                                                               ©Inbal Geffen 2012
Create Web Worker - 1
●   Web workers run from an external JS file
    (We will use a file called primesWorker.js as an example)

●   Web workers will be called from our HTML file

●   So we need two files : our HTML file and a JS file

●   Communication is done using messages : postMessage()

●   Ths JS file will have the function we would like to run on a different thread

●   The HTML file will:
     ○ Call the Web Worker (using javascript)
     ○ Respond to the Web Worker's messages
     ○ Change the UI



                                                                     ©Inbal Geffen 2012
Create Web Worker - 2
Main HTML file - create web worker

●   Create a new instance of web worker
    The worker gets the file name as a parameter
    var worker = new Worker("primesWorker.js");

●   If the file exists, a new thread will be asynchronously created

●   Calling the worker: postMessage()
    worker.postMessage(100);

●   postMessage() can get one parameter

●   This is the parameter that will be sent to the worker

●   So we see we can send messages to the worker from the HTML file

                                                                      ©Inbal Geffen 2012
Create Web Worker - 3
Main HTML file - get info from web worker

●   Getting messages FROM the worker


●   We need to listen to the 'message' event

worker.onmessage = function (e) {
        //do something with the message we got from the worker
        }




                                                                 ©Inbal Geffen 2012
Create Web Worker - 4
Main HTML file - errors

●   Check for errors

// Show errors from the worker
        worker.onerror = function (error) {
        alert(error.data);
        }




                                              ©Inbal Geffen 2012
Features Available to Workers
Due to their multi-threaded behavior, web workers only has access to a subset
of JavaScript's features:

 ●   The navigator object

 ●   The location object (contains information about the current URL)

 ●   XMLHttpRequest

 ●   setTimeout()/clearTimeout() and setInterval()/clearInterval()

 ●   Importing external scripts using the importScripts() method

 ●   Spawning other web workers


                                                                     ©Inbal Geffen 2012
Workers do NOT have access
 ●   The DOM (it's not thread-safe)

 ●   The window object

 ●   The document object

 ●   The parent object


That's why we need to communicate using messages.




                                                    ©Inbal Geffen 2012

More Related Content

What's hot

Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development PresentationTurnToTech
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedValency Networks
 
WEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptxWEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptxRajnirani18
 
Inline SVG - トラブルとその対策
Inline SVG - トラブルとその対策Inline SVG - トラブルとその対策
Inline SVG - トラブルとその対策Kohei Kadowaki
 
user Behavior Analysis with Session Windows and Apache Kafka's Streams API
user Behavior Analysis with Session Windows and Apache Kafka's Streams APIuser Behavior Analysis with Session Windows and Apache Kafka's Streams API
user Behavior Analysis with Session Windows and Apache Kafka's Streams APIconfluent
 
Unique ID generation in distributed systems
Unique ID generation in distributed systemsUnique ID generation in distributed systems
Unique ID generation in distributed systemsDave Gardner
 
Web Development and Web Development technologies - Temitayo Fadojutimi
Web Development and Web Development technologies - Temitayo FadojutimiWeb Development and Web Development technologies - Temitayo Fadojutimi
Web Development and Web Development technologies - Temitayo FadojutimiTemitayo Fadojutimi
 
MariaDB migration from commercial database
MariaDB migration from commercial databaseMariaDB migration from commercial database
MariaDB migration from commercial databaseGOTO Satoru
 
Progressive Web App
Progressive Web AppProgressive Web App
Progressive Web AppSubodh Garg
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENTkhushi74
 
まだ DOM 操作で消耗してるの?
まだ DOM 操作で消耗してるの?まだ DOM 操作で消耗してるの?
まだ DOM 操作で消耗してるの?Yuki Ishikawa
 
Metaverse building (blockchain, nft, 3d, vr)
Metaverse building (blockchain, nft, 3d, vr)Metaverse building (blockchain, nft, 3d, vr)
Metaverse building (blockchain, nft, 3d, vr)Wajdi Ben Rabah
 
Full stack web development
Full stack web developmentFull stack web development
Full stack web developmentCrampete
 
Introduction vulnérabilité web
Introduction vulnérabilité webIntroduction vulnérabilité web
Introduction vulnérabilité webdavystoffel
 

What's hot (20)

Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development Presentation
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting Explained
 
WEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptxWEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptx
 
Inline SVG - トラブルとその対策
Inline SVG - トラブルとその対策Inline SVG - トラブルとその対策
Inline SVG - トラブルとその対策
 
Web 3.0
Web 3.0Web 3.0
Web 3.0
 
user Behavior Analysis with Session Windows and Apache Kafka's Streams API
user Behavior Analysis with Session Windows and Apache Kafka's Streams APIuser Behavior Analysis with Session Windows and Apache Kafka's Streams API
user Behavior Analysis with Session Windows and Apache Kafka's Streams API
 
Unique ID generation in distributed systems
Unique ID generation in distributed systemsUnique ID generation in distributed systems
Unique ID generation in distributed systems
 
What is web scraping?
What is web scraping?What is web scraping?
What is web scraping?
 
Web Development and Web Development technologies - Temitayo Fadojutimi
Web Development and Web Development technologies - Temitayo FadojutimiWeb Development and Web Development technologies - Temitayo Fadojutimi
Web Development and Web Development technologies - Temitayo Fadojutimi
 
MariaDB migration from commercial database
MariaDB migration from commercial databaseMariaDB migration from commercial database
MariaDB migration from commercial database
 
Web dev syllabus
Web dev syllabusWeb dev syllabus
Web dev syllabus
 
Progressive Web App
Progressive Web AppProgressive Web App
Progressive Web App
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Druid+superset
Druid+supersetDruid+superset
Druid+superset
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
 
まだ DOM 操作で消耗してるの?
まだ DOM 操作で消耗してるの?まだ DOM 操作で消耗してるの?
まだ DOM 操作で消耗してるの?
 
Web3 Fundamentals
Web3 FundamentalsWeb3 Fundamentals
Web3 Fundamentals
 
Metaverse building (blockchain, nft, 3d, vr)
Metaverse building (blockchain, nft, 3d, vr)Metaverse building (blockchain, nft, 3d, vr)
Metaverse building (blockchain, nft, 3d, vr)
 
Full stack web development
Full stack web developmentFull stack web development
Full stack web development
 
Introduction vulnérabilité web
Introduction vulnérabilité webIntroduction vulnérabilité web
Introduction vulnérabilité web
 

Viewers also liked

Html5 storage suggestions for challenges.pptx
Html5 storage   suggestions for challenges.pptxHtml5 storage   suggestions for challenges.pptx
Html5 storage suggestions for challenges.pptxdeepmoteria
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web appsIvano Malavolta
 
Best Web-based Data Visualization tools
Best Web-based Data Visualization tools Best Web-based Data Visualization tools
Best Web-based Data Visualization tools Atchai
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local StorageLior Zamir
 
HTML5 Storage/Cache
HTML5 Storage/CacheHTML5 Storage/Cache
HTML5 Storage/CacheAndy Wang
 
PyCon 2012: Python for data lovers: explore it, analyze it, map it
PyCon 2012: Python for data lovers: explore it, analyze it, map it PyCon 2012: Python for data lovers: explore it, analyze it, map it
PyCon 2012: Python for data lovers: explore it, analyze it, map it Jacqueline Kazil
 
Personas: Understanding the User Behind the Visit
Personas: Understanding the User Behind the VisitPersonas: Understanding the User Behind the Visit
Personas: Understanding the User Behind the VisitMichael King
 
Cloud storage slides
Cloud storage slidesCloud storage slides
Cloud storage slidesEvan Powell
 

Viewers also liked (10)

Html5 storage suggestions for challenges.pptx
Html5 storage   suggestions for challenges.pptxHtml5 storage   suggestions for challenges.pptx
Html5 storage suggestions for challenges.pptx
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
 
Best Web-based Data Visualization tools
Best Web-based Data Visualization tools Best Web-based Data Visualization tools
Best Web-based Data Visualization tools
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
 
HTML5 Storage/Cache
HTML5 Storage/CacheHTML5 Storage/Cache
HTML5 Storage/Cache
 
Html5 web storage
Html5 web storageHtml5 web storage
Html5 web storage
 
PyCon 2012: Python for data lovers: explore it, analyze it, map it
PyCon 2012: Python for data lovers: explore it, analyze it, map it PyCon 2012: Python for data lovers: explore it, analyze it, map it
PyCon 2012: Python for data lovers: explore it, analyze it, map it
 
Html5-Web-Storage
Html5-Web-StorageHtml5-Web-Storage
Html5-Web-Storage
 
Personas: Understanding the User Behind the Visit
Personas: Understanding the User Behind the VisitPersonas: Understanding the User Behind the Visit
Personas: Understanding the User Behind the Visit
 
Cloud storage slides
Cloud storage slidesCloud storage slides
Cloud storage slides
 

Similar to Web Storage & Web Workers

Should you use HTML5 to build your product? The pros & cons of using current ...
Should you use HTML5 to build your product? The pros & cons of using current ...Should you use HTML5 to build your product? The pros & cons of using current ...
Should you use HTML5 to build your product? The pros & cons of using current ...boxuno
 
Make Mobile Apps Quickly
Make Mobile Apps QuicklyMake Mobile Apps Quickly
Make Mobile Apps QuicklyGil Irizarry
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGearsAlessandro Molina
 
Persistent Offline Storage White
Persistent Offline Storage WhitePersistent Offline Storage White
Persistent Offline Storage WhiteAlexei White
 
Introduction to Performance APIs
Introduction to Performance APIsIntroduction to Performance APIs
Introduction to Performance APIsShogo Sensui
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Per Henrik Lausten
 
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!ddrschiw
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Gil Irizarry
 
Node Web Development 2nd Edition: Chapter1 About Node
Node Web Development 2nd Edition: Chapter1 About NodeNode Web Development 2nd Edition: Chapter1 About Node
Node Web Development 2nd Edition: Chapter1 About NodeRick Chang
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash CourseHaim Michael
 
Brief history of web components
Brief history of web componentsBrief history of web components
Brief history of web componentsYevgeniy Valeyev
 
At Your Service - Abusing the Service Workers Web API
At Your Service - Abusing the Service Workers Web APIAt Your Service - Abusing the Service Workers Web API
At Your Service - Abusing the Service Workers Web APIDaniel Abeles
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATIONkrutitrivedi
 

Similar to Web Storage & Web Workers (20)

webworkers
webworkerswebworkers
webworkers
 
Should you use HTML5 to build your product? The pros & cons of using current ...
Should you use HTML5 to build your product? The pros & cons of using current ...Should you use HTML5 to build your product? The pros & cons of using current ...
Should you use HTML5 to build your product? The pros & cons of using current ...
 
Make Mobile Apps Quickly
Make Mobile Apps QuicklyMake Mobile Apps Quickly
Make Mobile Apps Quickly
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
 
Persistent Offline Storage White
Persistent Offline Storage WhitePersistent Offline Storage White
Persistent Offline Storage White
 
Introduction to Performance APIs
Introduction to Performance APIsIntroduction to Performance APIs
Introduction to Performance APIs
 
Sprint 17
Sprint 17Sprint 17
Sprint 17
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)
 
Web worker
Web workerWeb worker
Web worker
 
WP - Unit I.ppt
WP - Unit I.pptWP - Unit I.ppt
WP - Unit I.ppt
 
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
Ad108 - XPages in the IBM Lotus Notes Client - A Deep Dive!
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
 
Node Web Development 2nd Edition: Chapter1 About Node
Node Web Development 2nd Edition: Chapter1 About NodeNode Web Development 2nd Edition: Chapter1 About Node
Node Web Development 2nd Edition: Chapter1 About Node
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
 
HTML5 Web storage
HTML5 Web storageHTML5 Web storage
HTML5 Web storage
 
Polymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot CampPolymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot Camp
 
Brief history of web components
Brief history of web componentsBrief history of web components
Brief history of web components
 
At Your Service - Abusing the Service Workers Web API
At Your Service - Abusing the Service Workers Web APIAt Your Service - Abusing the Service Workers Web API
At Your Service - Abusing the Service Workers Web API
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 

More from Inbal Geffen

More from Inbal Geffen (9)

Css3
Css3Css3
Css3
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Jquery mobile2
Jquery mobile2Jquery mobile2
Jquery mobile2
 
Jquery2
Jquery2Jquery2
Jquery2
 
J querypractice
J querypracticeJ querypractice
J querypractice
 
J queryui
J queryuiJ queryui
J queryui
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
jQuery mobile UX
jQuery mobile UXjQuery mobile UX
jQuery mobile UX
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 

Recently uploaded

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Web Storage & Web Workers

  • 1. HTML5 Web Storage (DOM storage) ©Inbal Geffen 2012
  • 2. Why? ● HTTP is stateless ● We want to keep record of what the user did ● We want to be able to work "offline" ● We don't want to force users to signup / login ©Inbal Geffen 2012
  • 3. Cookies ● Used before HTML5 Web Storage ● 4KB memory limitation per cookie ● Sent in every request ● Have a "bad reputation" ©Inbal Geffen 2012
  • 4. localStorage vs. sessionStorage In Both ● Data is stored as key/value pairs ● Data is stored in string form ● Use the same API : setItem(), getItem(), clear(), removeItem() ● Fire 'storage' event ©Inbal Geffen 2012
  • 5. localStorage vs. sessionStorage Differ in scope and lifetime ● sessionStorage is stored until the window is closed ● localStorage is stored until the storage is cleared ● localStorage is synchronized within the browser windows and tabs ● sessionStorage - multiple instances of the same window without collision ©Inbal Geffen 2012
  • 6. Web Storage Support ● We must remember that not all browsers support "Web Storage" function checkStorageSupport() { if (!window.localStorage) { alert('This browser does NOT support localStorage'); } } ©Inbal Geffen 2012
  • 7. Web Storage API setItem //set Item in local storage localStorage.setItem("userName", userName); //can also use immediate set, but this is less recommended localStorage.userName=userName; //set Item in session storage sessionStorage.setItem("userName", userName); //can also use the immediate set, but this is less recommended sessionStorage.userName=userName; ©Inbal Geffen 2012
  • 8. Web Storage API getItem //get Item in local storage var userName = localStorage.getItem("userName); //can also use immediate get, but this is less recommended var userName = localStorage.userName; //get Item in session storage sessionStorage.getItem("userName); //can also use the immediate set, but this is less recommended var userName = sessionStorage.userName; ©Inbal Geffen 2012
  • 9. Web Storage API clear(), removeItem //clear the local storage localStorage.clear(); //remove specific item from local storage localStorage.removeItem("userName"); //localStorage.getItem("userName") => NULL //clear the session storage sessionStorage.clear(); //remove specific item from session storage sessionStorage.removeItem("userName"); ©Inbal Geffen 2012
  • 10. Web Storage API ● Web Storage is an array ● localStorage.length ● Item in the ith position in the array : localStorage.key(i) ©Inbal Geffen 2012
  • 11. Storage Event //Fired when performing an operation on the storage if (window.addEventListener) { window.addEventListener("storage", handleStorageEvent, false); } else { // for IE versions below IE9 window.attachEvent("onstorage", handleStorageEvent); }; function handleStorageEvent(eventData) { // Do something } ©Inbal Geffen 2012
  • 12. Things to remember • Local storage persists until it is deleted or the browser’s cache is cleared. • Session storage persists until it is deleted or the browsing context is closed. • Data stored by one browser is not accessible by another browser. For example, data stored by Chrome is not seen by Firefox. • Objects should be stored as strings. • For security reasons, sensitive data should not be stored, especially in local storage. • Changes to a storage area cause a “storage” event to be fired. • As with many other HTML5 features, web storage is not yet implemented consistently. ©Inbal Geffen 2012
  • 13. HTML5 Web Workers ©Inbal Geffen 2012
  • 14. THE PROBLEM: JAVASCRIPT CONCURRENCY • JavaScript is a single-threaded environment • Used to be "solved" with asynchronous techniques such as: setTimeout(), setInterval(), XMLHttpRequest, and event handlers • Asynchronous events are processed after the current executing script • Web Workers are the HTML5 solution, enabling multi threading ©Inbal Geffen 2012
  • 15. Web Workers - Use Cases Doing an action/process on the background, without harming the UI Show something to the user and then we can update the UI with the result. ● Updating many rows of local web database ● Processing large arrays ● Background I/O - fetch data for later ● Spell checker ● Code syntax highlighting or other real-time text formatting ©Inbal Geffen 2012
  • 16. Web Workers Support ● We need to remember to check browser support for web workers function checkWorkerSupport() { if (typeof(window.Worker) === "undefined") alert("Your browser doesn't support HTML5 Web Workers!"); } ©Inbal Geffen 2012
  • 17. Create Web Worker - 1 ● Web workers run from an external JS file (We will use a file called primesWorker.js as an example) ● Web workers will be called from our HTML file ● So we need two files : our HTML file and a JS file ● Communication is done using messages : postMessage() ● Ths JS file will have the function we would like to run on a different thread ● The HTML file will: ○ Call the Web Worker (using javascript) ○ Respond to the Web Worker's messages ○ Change the UI ©Inbal Geffen 2012
  • 18. Create Web Worker - 2 Main HTML file - create web worker ● Create a new instance of web worker The worker gets the file name as a parameter var worker = new Worker("primesWorker.js"); ● If the file exists, a new thread will be asynchronously created ● Calling the worker: postMessage() worker.postMessage(100); ● postMessage() can get one parameter ● This is the parameter that will be sent to the worker ● So we see we can send messages to the worker from the HTML file ©Inbal Geffen 2012
  • 19. Create Web Worker - 3 Main HTML file - get info from web worker ● Getting messages FROM the worker ● We need to listen to the 'message' event worker.onmessage = function (e) { //do something with the message we got from the worker } ©Inbal Geffen 2012
  • 20. Create Web Worker - 4 Main HTML file - errors ● Check for errors // Show errors from the worker worker.onerror = function (error) { alert(error.data); } ©Inbal Geffen 2012
  • 21. Features Available to Workers Due to their multi-threaded behavior, web workers only has access to a subset of JavaScript's features: ● The navigator object ● The location object (contains information about the current URL) ● XMLHttpRequest ● setTimeout()/clearTimeout() and setInterval()/clearInterval() ● Importing external scripts using the importScripts() method ● Spawning other web workers ©Inbal Geffen 2012
  • 22. Workers do NOT have access ● The DOM (it's not thread-safe) ● The window object ● The document object ● The parent object That's why we need to communicate using messages. ©Inbal Geffen 2012