Reputation: 147
Is there a library to help storing the javascript and css files at client for speed up the pages? Is webstorage (HTML5 def) usefull for this case?
Upvotes: 0
Views: 396
Reputation: 5915
HTTP resources like stylesheet and script files are cached (IETF) by the browser if not modified (status 304); for that, no library is needed.
On the other hand, feel free to make extensive use of the Storage
interface. Depending on your use case, it could be advisable to store large custom data (like the data for a result page as stringified
JSON), so that it can be displayed instantaneously while up-to-date data is fetched in the background. JavaScript data can be conveniently stored. Concerning CSS, it might be a bit of a hassle.
There’s still more related HTML5 techniques, like link prefetching or the app cache (using a resource manifest) for offline apps.
Upvotes: 0
Reputation: 478
This is true that the browser by default cache your css and js file but if you want to explicitly cache it for offline use as well you can use the HTML5 manifest feature where you can create a manifest file and specify the files you wan to cache like this
CACHE MANIFEST
# rev 3
CACHE:
index.html
app.html
js/data.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css
http://code.jquery.com/jquery-1.4.3.min.js
js/script.js
style.css
images.png
these files will be cached after they are downloaded once at the first request which will save your load time in future. You can also specify fallback for your css and js files, refer this link to understand the basics of manifest.
Upvotes: 0
Reputation: 1033
For really big scripts you can store it in LocalStorage and load it via eval. BUT: HTTP caches default if your headers are set correctly - You should prevent inline scriptcode then.
Upvotes: 0
Reputation: 944442
You don't need a library for that. Standard HTTP caching will allow you to ask a browser to store a local copy.
Cache-Control: max-age=604800, must-revalidate
Upvotes: 3