Using window.name as a local data cache in web browsers
Asked Answered
M

2

14

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

Masochism answered 9/1, 2010 at 21:44 Comment(2)
is that 10kb of compressed JSON?Orthogenetic
10K uncompressed and rather verbose.Masochism
C
5

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.

Commercial answered 9/1, 2010 at 21:44 Comment(0)
L
2

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).

Laity answered 9/1, 2010 at 21:44 Comment(1)
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.Dyer

© 2022 - 2024 — McMap. All rights reserved.