SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
HTML5 localStorage
by yz
function() {
!
var name=
document.getElementById('name').value;
!
!
localStorage.setItem('name', name);!
});
What is local storage?
• data stored in your local computer

=> faster loading :)
• data persists even after you navigate away from the
web site, close your browser tab, exit your browser,
• Cookies and cache are also local storage
review: cache and cookies
• Cache: a temporary storage of web page
resources stored on client’s machine

for quicker loading of the web pages!
• Cookies: a very small piece of information that is
stored on the client’s machine by the web site and
is sent back to the server each time a page is
requested to store information 

for tracking different characteristics related to
user
HTML5 Local Storage
it’s a way for web pages to store named key/value pairs

locally, within the client web browser
Is it different from Cache or
Cookies?
• Cache: speed up loading the page (video, audio,
text messages)
• Cookies: store info about the user
!
• localStorage: store info about the user
to use on the server side
to use on the client side
Is it different from Cache or
Cookies?
• Cookie: user info to be used on the server side
• localStorage: user info to be used on the client
side
function() {
!
var name=
document.getElementById('name').value;
!
!
localStorage.setItem('name', name);!
});
get ‘/’ do
!
@user =
User.find(session[:id])
erb: index
end
Is it different from Cache or
Cookies?
• Cookie: limited to 4 KB of data
• localStorage: 5MG of data
Is it different from Cache or
Cookies?
• Cookie: sent in every HTTP request
• localStorage: not sent in request
How to use localStorage
• Set the key & value pair!
• Retrieve the data!
• Remove the data!
function() {
!
var name=
document.getElementById('name').value;
!
!
localStorage.setItem('name', name);!
});
<input type="name" name="name" id=“name">
Set the key & value pair!
localStorage[“name”] = name
window.onload = function() {
var name = localStorage.getItem('name');
!
if (name != "undefined" || name != "null") {
document.getElementById('welcomeMessage').innerHTML = "Hello " +
name + "!";
} else
document.getElementById('welcomeMessage').innerHTML = "Hello!";
}
}
Retrieve the data!
localStorage[“name”]
localStorage.removeItem('name');
Remove the data!
localStorage.clear();
Summary
• wanna get a lot of user information and use it on
the client side ?

=> use localStorage!
• set, retrieve, remove the data!



localStorage.setItem(“key”,”value”)

localStorage[“key”]


Contenu connexe

Tendances

CouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy serverCouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy server
tkramar
 
On the incoherencies in web browser access control
On the incoherencies in web browser access controlOn the incoherencies in web browser access control
On the incoherencies in web browser access control
UT, San Antonio
 

Tendances (10)

Displaying message on web page in Javascript
Displaying message on web page in JavascriptDisplaying message on web page in Javascript
Displaying message on web page in Javascript
 
HTML5
HTML5HTML5
HTML5
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Introduction to html & css
Introduction to html & cssIntroduction to html & css
Introduction to html & css
 
Geek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual DatabaseGeek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual Database
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
 
Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2
Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2
Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2
 
CouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy serverCouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy server
 
On the incoherencies in web browser access control
On the incoherencies in web browser access controlOn the incoherencies in web browser access control
On the incoherencies in web browser access control
 

Similaire à Lt local storage

19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
Chhom Karath
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environment
vmaximiuk
 

Similaire à Lt local storage (20)

Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
 
javaScriptCookies.pptx
javaScriptCookies.pptxjavaScriptCookies.pptx
javaScriptCookies.pptx
 
APEX & Cookie Monster
APEX & Cookie MonsterAPEX & Cookie Monster
APEX & Cookie Monster
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
 
Cookies & Session
Cookies & SessionCookies & Session
Cookies & Session
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails application
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Accelerating Rails with edge caching
Accelerating Rails with edge cachingAccelerating Rails with edge caching
Accelerating Rails with edge caching
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environment
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
Session and cookies,get and post
Session and cookies,get and postSession and cookies,get and post
Session and cookies,get and post
 
State Management.pptx
State Management.pptxState Management.pptx
State Management.pptx
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Lt local storage

  • 3. What is local storage? • data stored in your local computer
 => faster loading :) • data persists even after you navigate away from the web site, close your browser tab, exit your browser, • Cookies and cache are also local storage
  • 4. review: cache and cookies • Cache: a temporary storage of web page resources stored on client’s machine
 for quicker loading of the web pages! • Cookies: a very small piece of information that is stored on the client’s machine by the web site and is sent back to the server each time a page is requested to store information 
 for tracking different characteristics related to user
  • 5. HTML5 Local Storage it’s a way for web pages to store named key/value pairs
 locally, within the client web browser
  • 6. Is it different from Cache or Cookies? • Cache: speed up loading the page (video, audio, text messages) • Cookies: store info about the user ! • localStorage: store info about the user to use on the server side to use on the client side
  • 7. Is it different from Cache or Cookies? • Cookie: user info to be used on the server side • localStorage: user info to be used on the client side function() { ! var name= document.getElementById('name').value; ! ! localStorage.setItem('name', name);! }); get ‘/’ do ! @user = User.find(session[:id]) erb: index end
  • 8. Is it different from Cache or Cookies? • Cookie: limited to 4 KB of data • localStorage: 5MG of data
  • 9. Is it different from Cache or Cookies? • Cookie: sent in every HTTP request • localStorage: not sent in request
  • 10. How to use localStorage • Set the key & value pair! • Retrieve the data! • Remove the data!
  • 11. function() { ! var name= document.getElementById('name').value; ! ! localStorage.setItem('name', name);! }); <input type="name" name="name" id=“name"> Set the key & value pair! localStorage[“name”] = name
  • 12. window.onload = function() { var name = localStorage.getItem('name'); ! if (name != "undefined" || name != "null") { document.getElementById('welcomeMessage').innerHTML = "Hello " + name + "!"; } else document.getElementById('welcomeMessage').innerHTML = "Hello!"; } } Retrieve the data! localStorage[“name”]
  • 14. Summary • wanna get a lot of user information and use it on the client side ?
 => use localStorage! • set, retrieve, remove the data!
 
 localStorage.setItem(“key”,”value”)
 localStorage[“key”]