views:

252

answers:

2

I was reading about cookies and other related client-side storage options, and read about using window.name as a data cache of sorts:

http://en.wikipedia.org/wiki/HTTP_cookie#window.name

While it certainly has things that make it less desirable - and I won't sugar coat it, it is definitely a hack in the most true sense of that word - it looks promising. I have a need to store about 10K of JSON as a client cache, right now I am sending it down with the page and when I read about this it seems like it might actually fit my needs and reduce traffic.

I am curious to see if anyone has implemented this, and what advice you could possibly give. Pitfalls? Recommendations? Differences between browsers? Some sort of usage case that would be really bad?

Pros

  • Local storage
  • Available in basically every browser that supports javascript

Cons

  • Only supports strings
  • XSS Issues
  • window.name poisoning
  • Information leaking to other sites

Alternatives

+2  A: 

This seems to be first implemented here: http://www.thomasfrank.se/sessionvars.html.

However, if this technique takes off, I would bet money that the browsers would eventually crack down on it due to its inherit vulnerability to XSS.

A more long term solution is likely to be: http://en.wikipedia.org/wiki/DOM_storage which grew out of the HTML 5 specification (the biggest drawback being the lack of backwards compatibility for browsers before IE 8).

Rob Van Dam
Agreed, as something that isn't explicitly documented/standardised it's best not relied on... but could be a useful fallback for browsers that don't support better alternatives.
bobince
+3  A: 

There are many ways to store local data, Flash LSO, HTML 5 Local Storage, cookies. Google gears. Have a look at PersistJS, a js client library that will just do it.

This post in Ajaxian elaborates a little more about it.

Sug