5 ms·
Basket.js: A simple script loader that caches scripts with localStorage
- legacye 15y agoHey 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.
- grayrest 15y agoBe 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.
- deleted 15y ago[deleted]
- maratd 15y agoYou're better off using a manifest file, which is part of the HTML5 spec. Not everything needs to be done in JavaScript =)
- SMrF 15y agoDoesn'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 15y agoI 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.
- maratd 15y agoIt is my understanding that desktop browsers do present the prompt, but mobile browsers do not. This feature was mostly designed for mobile, since the browser cache in mobile tends to be constrained. I have a feeling as things move along, that prompt will go away entirely.
- maxwell 15y agoBut it will be eventually be written in JavaScript.
- pygy_ 15y agoThere's an extra HTTP request to fetch the manifest on every page load. In the same vein, does the browser check if files specified in the manifest expired? If yes it would once again waste some time...
- asjustas 15y agohttp://en.wikipedia.org/wiki/Cache_manifest_in_HTML5 http://en.wikipedia.org/wiki/Cache_manifest_in_HTML5
- SMrF 15y agoI 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 15y agoCaching 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.
- ootachi 15y agoPlease 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-api http://paul.kinlan.me/we-need-to-kill-off-the-localstorage-a...