2 ms·
I have to agree. As nice as these kinds of systems sound (I've designed experimental ones myself), in most applications its just not the right way to handle it.
by geuis 15y ago
I have to agree. As nice as these kinds of systems sound (I've designed experimental ones myself), in most applications its just not the right way to handle it. The first gotcha is that localStorage isn't async itself. If you have lots of data that has to be pulled out or stored, you might end up locking up the thread and bring the rest of the app to a standstill.
Another important issue is that all browsers already have caching mechanisms built in. Spend your time verifying and correcting that your headers are being set properly for your js and stylesheets.
Also, localStorage only gives you 5mb of storage. That space can be taken up very quickly if you aren't careful.
There are some very limited cases where this kind of thing can be useful. One that I'm reminded of is mobile web applications. Steve Souders talked about this briefly at the jQuery conference around this time last year. However, all the major mobile browsers already support cache manifests, which mostly obviates the need for something like this.
- d0ugal 15y agoI agree, its not a good approach in general. Correct cache headers on the server is probably the way to go in many cases. I originally created this handle working with an external API in a simple static files only app. It works really well for that usecase and solved my issues. It was then easy to make in a general way, so I decided to chuck it out in the wild and see if I can help anybody else. Perhaps I should add an area to the README to define when you should (and maybe more importantly when you shouldn't) use this.