What is HTML5 Web Storage? Explain localStorage and sessionStorage .
What is HTML5 Web Storage? Explain localStorage and sessionStorage .
HTML5 Web Storage is a feature that allows web applications to store data locally within the user's browser. This capability provides a way to store key-value pairs on the client side, offering a significant improvement over older methods like cookies, which were limited in size and automatically sent with every server request. Web Storage is part of the HTML5 specification and is designed to be more secure and capable of handling larger amounts of data[13][15].
localStorage
is a type of web storage that allows data to be stored across browser sessions. Data stored in localStorage
does not expire; it remains stored on the user's device even after the browser is closed and reopened. This makes localStorage
suitable for storing data that needs to persist long-term, such as user preferences or application state[1][5].
Key characteristics of localStorage
include:
localStorage
is specific to the protocol, domain, and port of the page that stored it, adhering to the same-origin policy.localStorage
is accessible only by client-side scripts from the same origin, it is not encrypted and should not be used to store sensitive information due to potential risks from cross-site scripting (XSS) attacks[16].sessionStorage
, on the other hand, is designed for storing data that should only persist for the duration of the page session. This means that the data stored in sessionStorage
is cleared when the page session ends, which is typically when the browser tab is closed[8][17].
Key characteristics of sessionStorage
include:
localStorage
, sessionStorage
generally supports about 5 MB of data per origin.middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào