

Store.js - cross browser local storage without using cookies or flash - narcvs
http://github.com/marcuswestin/store.js

======
Myrth
It would be nice to know limitations (by browser/version?)

I.e. maximum storage size, scope (global, 2nd level domain, any domain), life
cycle (when is it cleared), etc.

------
kenpratt
Lawnchair (<http://brianleroux.github.com/lawnchair/>) is similar to this, but
you have to pick an adapter (see <http://github.com/brianleroux/lawnchair> for
browser list).

~~~
mblakele
In the past I have used PersistJS (<http://pablotron.org/?cid=1557>) for this.
Are there reasons to prefer one or the other of these libraries?

~~~
marcuswestin
PersistJS is 12kb minified. store.js is 4kb unminified

PersistJS falls back on flash and cookies, which is bad (flash slows down
browser during page loading, cookies fatten your network requests). Store.js
uses localStorage, globalStorage and IE behaviors which do not have those
negative side effects.

------
barredo
From the readme:

"So far tested in

Tested in Firefox 2.0 Tested in Firefox 3.0 Tested in Firefox 3.6 Tested in
Chrome 5 Tested in Safari 4 Tested in Safari 5 Tested in IE6 Tested in IE7
Tested in IE8 Tested in Opera 10"

Does it mean it works on IE6+? Does IE6 have local storage?

~~~
cheald
Take a look at the source. It uses an IE-proprietary something or other to
mock the behavior.

[http://msdn.microsoft.com/en-
us/library/ms531424%28v=VS.85%2...](http://msdn.microsoft.com/en-
us/library/ms531424%28v=VS.85%29.aspx)

Been available since IE 5.5, apparently. Who knew?

~~~
barredo
Really awesome. I did check the source, but did not quite understand that.
Thanks!

------
n8agrin
It seems as though the author does not believe in semicolon use in Javascript.
Looks interesting though.

~~~
marcuswestin
I use semicolons when they're needed (for loops, multiple statements per
line), and don't use them when they're not. The code becomes cleaner to my
eyes.

~~~
gnaritas
They're always needed so the JavaScript can be run through a compressor for
production deployment without breaking the code.

Beyond that you're using curly braces when they're not strictly required,
which seems inconsistent. I would expect either both all the time or both only
when strictly necessary.

~~~
timknauf
Surely if the language specification calls semicolons optional then any
compressor worth its salt should honor that? The YUI Compressor, at least,
copes with semicolon-devoid Javascript just fine.

~~~
gnaritas
That's the sufficiently smart compiler argument. The fact remains you have
more options available to you for minifying if you don't consider semi-colons
optional, naming one compressor that can deal doesn't change the fact that
most can't.

------
chip
Do you plan to add length? ie localstorage.length, etc. I'll like to implement
this on <http://readmelater.com>

Looks great by the way!

------
empire29
Anyone know of size limitations on this storage? I am in the middle of writing
a jQuery plugin and storing data in cookies which have the 4KB size limitation
(which resulted in me having to "chunk" the data across several cookies). This
looks like the perfect alternative!

~~~
Groxx
I think Safari defaults to 10MB, though I may have changed it and forgotten
doing so.

------
tobyhede
For a different take on local storage, have a look at MilkCrate
<http://github.com/garrow/milkcratejs>

MilkCrate is a wrapper around html localStorage/globalStorage that provides
support for saving and querying collections of objects. MilkCrate attempts to
implement a similar querying interface to mongoDB.

------
Dylan16807
It works now that I stuck it on a server, but apparently FF3.6.4 drops the
data between passes on a file:// url. IE6 and Opera10 hang on to it, nothing
else available here.

------
paraschopra
I just tested. Like cookies, it also obeys domain-only visibility. So, all
hopes for cross-domain user tracking are still doomed. _sigh_

~~~
Groxx
(to repliers)

</sarcasm>

~~~
lanstein
This was one of the less obvious uses of sarcasm in recent memory.

~~~
Groxx
It's entirely possible I'm wrong, but I'm hinging my decision largely on the
location (hn, where invasive user tracking is synonymous with evil with nearly
_everyone_ ) and the " _sigh_ ".

------
wolfhumble
Tested it on IE 6 and got: "Tests passed" So I guess it works . . . :-)

~~~
narcvs
Yup, it works in IE6.

I don't have access to IE5.5, would love to have someone test it.

~~~
cheald
Give IETester a whirl. IE 5.5, 6, 7, 8, and 9 preview render engines in a
single executable.

<http://www.my-debugbar.com/wiki/IETester/HomePage>

~~~
marcuswestin
I'm not convinced that IETester changes the underlying APIs correctly. Because
of bad experience with "Multiple IE" simulators in the past I don't test on
anything but the real install.

~~~
cheald
I hear you there. I just wish it were easier to have multiple versions of IE
laying around without having to boot a VM for each. Heh.

~~~
scommab
ThinApp [<http://en.wikipedia.org/wiki/VMware_ThinApp>] is pretty useful when
needing to do "classic" browser testing.

~~~
TeHCrAzY
I don't think many people would be willing to invest $6,000 USD (minimum!) to
test old versions of IE.

------
eli
In theory localStorage should work on iPhone and Android 2.0+ too

------
erlanger

      Fix issue 1, rename store.del() to store.remove()
      marcuswestin (author)
      18 minutes ago
    

Will the API be stabilized? Or can you alias method names in cases like this,
rather than clobbering them?

~~~
alunny
It's a sixty line JS file that's been online for less than a day. I don't
think API stability is a major concern at this point.

