I want to store some data client side. Cookies are my first inclination, but they get sent with every request, right? Is th开发者_运维问答ere a way to store data without it being transferred? I don't necessarily want to add 10-20k of overhead for every request. Is the only alternative HTML 5 webstorage and how many browsers have adopted that?
html5 storage is widely deployed
HTML5 STORAGE SUPPORT
IE FIREFOX SAFARI CHROME OPERA IPHONE ANDROID
8.0+ 3.5+ 4.0+ 4.0+ 10.5+ 2.0+ 2.0+
you can find out more @ http://diveintohtml5.ep.io/storage.html
No, not all cookies get sent with every request. You can check to see if a cookie exists, if not create it, and if so, read it. Cookies are still a good cross-browser option for small amounts of data.
http://fsojs.com supports robust file storage client-side, but only works with Chrome at the moment
As you have mentioned, cookies are an options and so is web storage in the HTML5 spec. There's also the ability to use Flash to store data with the added benefit that this data persists across multiple browsers on the same machine, but the drawback that you'll need a fallback for users who don't have Flash.
Personally, keeping the data on the server (identified by the session id or cookie) would be my way to do it, you have control of the data and don't have to worry about losing it when the user clears their cache or switches machines/devices. It's also the most fault-tolerant because it doesn't rely on browser features and/or plugins (other than perhaps cookies).
One more thing, if you're looking for an abstraction of client-side data storage that uses all of the above (cookies, flash, web storage) check out Evercookie
精彩评论