TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Basket.js: A simple script loader that caches scripts with localStorage

52 pointsby abrahamabout 13 years ago

6 comments

SMrFabout 13 years ago
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.<p>IMHO, edge cases aside, most people shouldn't do this.
评论 #3658429 未加载
grayrestabout 13 years ago
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.
legacyeabout 13 years ago
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.
maratdabout 13 years ago
You're better off using a manifest file, which is part of the HTML5 spec. Not everything needs to be done in JavaScript =)
评论 #3657916 未加载
评论 #3657788 未加载
评论 #3657439 未加载
ootachiabout 13 years ago
Please don't use local storage. It's synchronous and will hang the entire browser or tab while the script is loading: <a href="http://paul.kinlan.me/we-need-to-kill-off-the-localstorage-api" rel="nofollow">http://paul.kinlan.me/we-need-to-kill-off-the-localstorage-a...</a>
asjustasabout 13 years ago
<a href="http://en.wikipedia.org/wiki/Cache_manifest_in_HTML5" rel="nofollow">http://en.wikipedia.org/wiki/Cache_manifest_in_HTML5</a>