Câu hỏi phỏng vấn HTML
Câu hỏi

What is HTML5 Web Storage? Explain localStorage and sessionStorage .

Câu trả lời

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

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:

  • Persistence: Data remains until explicitly deleted by the user or the web application.
  • Capacity: Most browsers support at least 5 MB of data per origin.
  • Scope: Data stored in localStorage is specific to the protocol, domain, and port of the page that stored it, adhering to the same-origin policy.
  • Security: While 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

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:

  • Session-only lifespan: Data is only available for the duration of the browser tab's life.
  • Capacity: Like localStorage, sessionStorage generally supports about 5 MB of data per origin.
  • Scope: Data is accessible only within the same tab or window that created it, even if another tab or window is opened with the same page.
  • Use cases: `session...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What does a DOCTYPE do?

middle

Explain the difference between cookies, session and local storage

senior

What is progressive rendering?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào