HTML and CSS Reference
In-Depth Information
Looking at how cookies work, they're overly complicated. Setting
a cookie in JavaScript looks like this:
document.cookie = “foo=bar; path=/”;
That's a session-based cookie. Now, if I want to store something
for longer, I'll have to set it in the future, and give it a specific
lifetime (and if I want it to persist, I'll have to keep setting this to
be n days in the future):
document.cookie = “foo=bar; path=/; expires=Tues,
¬ 13 Sept 2010 12:00:00”;
The time format is important too, which only causes more head-
aches. Now, the icing on the horrible-tasting cookie—to delete
a cookie, I need to set the value to blank:
document.cookie = “foo=; path=/”;
In fact, the cookie isn't really deleted, it's just had the value
changed and had the expiry set to the current session (that is,
when the browser is shut down). Delete should really mean delete.
Cookies don't work because they're a headache. The new
storage specifications completely circumvent this cumbersome
approach to setting, getting, and removing data by offering a
clean API.
Being British though, I feel I need to add a caveat to the “cook-
ies suck” statement. But fear not—it's only a small caveat. If you
need to share client-side data with the server side, cookies are
the right solution because they append themselves to every
request automatically. If you don't, then you want a client-side
storage engine. To me, Web Storage evolved as cookies should
have, but Web Storage has even more functionality, hence the
evolution. So with my caveat aside, let's look at what today's
browsers have in store for us (pardon the pun)!
NoTE Get Peter-Paul
Koch's cookie code at
www.quirksmode.org/js/
cookies.html .
Storage options
There are three options when it comes to storing data on the
client side:
Web Storage—supported in all the latest browsers—
http://www.w3.org/TR/webstorage/
Web SQL Database—supported in Opera, Chrome, and Safari—
http://www.w3.org/TR/webdatabase/
 
 
Search WWH ::




Custom Search