Introducing HTML5 Storage
What I refer to as âHTML5 Storageâ is actually a specification named Web Storage. This was at one time part of the HTML5 specification proper, but was split out into its own specification for uninteresting political reasons. Certain browser vendors also refer to it as âLocal Storageâ or âDOM Storage.â The naming situation is made even more complicated by some related, similarly named, emerging standards that Iâll discuss later in this chapter.
So what is HTML5 Storage? Simply put, itâs a way for web pages to store named key/value pairs locally, within the client web browser. Like the data stored in cookies, this data persists even after you navigate away from the website, close your browser tab, exit your browser, or what have you. But unlike with cookies, this data is never transmitted to the remote web server (unless you go out of your way to send it manually). And unlike all previous attempts at providing persistent local storage (described in the preceding section), it is implemented natively in web browsers, so it is available even when third-party browser plug-ins are not.
Which browsers? As Table 7-1 shows, HTML5 is supported by the latest versions of pretty much all browsers...even Internet Explorer!
Table 7-1. HTML5 Storage support
IE | Firefox | Safari | Chrome | Opera | iPhone | Android |
---|---|---|---|---|---|---|
8.0+ | 3.5+ | 4.0+ | 4.0+ | 10.5+ | 2.0+ | 2.0+ |
From your JavaScript code, youâll access HTML5
Storage through the localStorage
object
on the global window
object. Before you can ...
Get HTML5: Up and Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.