Vini.g.fer
Vini.g.fer

Reputation: 11909

HTML5 local storage - Store and load CSS that has been downloaded once

I would like to know if it's possible to do the following: Store CSS and/or JavaScript files using HTML5 local storage, and when a page is accessed again use the files stored locally instead of downloading them once again from the web.

This can be usefull for webApps running on 3G, to reduce the amount of data to download.

However, I'm not sure if those files can be accessed during page load. Anyone know about this?

Upvotes: 3

Views: 928

Answers (3)

Andreas Köberle
Andreas Köberle

Reputation: 110902

You should use the cache manifest file instead of localStorage

Upvotes: 4

Christoph
Christoph

Reputation: 51201

This would be possible however this is quite costly since on pageload you have to manually load the string, convert it to a style/script and insert it into the DOM so it get's recognized by the browser. Also there might be the case that a browser does not support localStorage or the User blocked your access to it.

It's better to set the cache directives accordingly with meta tags and/or cache manifest - also browser will normally cache your files automatically by themselves.

Upvotes: 1

Bill Gregg
Bill Gregg

Reputation: 7147

Generally browsers cache CSS files for you automatically. Even in mobile.

Upvotes: 1

Related Questions