

Basket.js: A simple script loader that caches scripts with localStorage - abraham
http://addyosmani.github.com/basket.js/

======
SMrF
I feel like using localStorage to cache stuff that could be handled by http
caching is probably a mistake. I'm in the process of caching a bunch of our
application in localStorage because a quirk in our client-side architecture
means I need to know if something is cached before making an asynch request
for content, (which you can't do with the standard http cache). That means I'm
reinventing a cache invalidation scheme -- which we all know is hard, right?
Plus the space allocated for localStorage is pretty small, so I have to have a
way to prioritize the cache and bump out old stuff to make way for new. It's
all rather convoluted.

IMHO, edge cases aside, most people shouldn't do this.

~~~
shantanubala
Caching assets in localStorage definitely isn't a "best practice," and seems
like something that should only be done when necessary.

One of the best uses for localStorage though, is caching client-side
templates. If you're building an app that's got a ton of different models and
templates for each one, it makes your application a lot more efficient to
lazy-load them as needed and cache them in localStorage for later use with
versioning and cache invalidation.

------
grayrest
Be aware that localStorage is synchronous and browsers currently load the
entire localStorage for a domain into memory to satisfy the first request.
Shouldn't be a problem here but something to be aware of.

------
legacye
Hey guys - I wrote this. Just to point out: this project is really just a
proof of concept. I haven't personally seen any figures to suggest that
localStorage caching is more optimal than standard browser caching, but once
these benchmarks are available (hoping to get them up on jsPerf), they'll be
posted to the same page.

------
maratd
You're better off using a manifest file, which is part of the HTML5 spec. Not
everything needs to be done in JavaScript =)

~~~
SMrF
Doesn't the using the application cache (e.g. the manifest file you speak of)
cause a user prompt? That's a deal breaker in many situations.

~~~
karol
I am using a manifest in my new app and never witnessed a user prompt. I am
testing on Android 2.2 native browser, chrome and safari.

------
ootachi
Please don't use local storage. It's synchronous and will hang the entire
browser or tab while the script is loading: [http://paul.kinlan.me/we-need-to-
kill-off-the-localstorage-a...](http://paul.kinlan.me/we-need-to-kill-off-the-
localstorage-api)

------
asjustas
<http://en.wikipedia.org/wiki/Cache_manifest_in_HTML5>

