简体   繁体   中英

How to save html, javascript and css files in html5 local storage?

Is there a way to store a html, javascript and css files in html5 local storage?

I want make my webapplication faster!

Thanks

You want to use the Application Cache for this, not localStorage:

http://www.html5rocks.com/en/tutorials/appcache/beginner/

You don't use HTML5 Local storage for CSS/JS files in, you cache them.

I suggest to use cache on client and server side instead of storing in local storage this way you have control on when to update(invalidate cache), you can also consider using CDN to deliver static content like images, js, css

Even though it's not the best solution, it is possible to cache most of the interface with local storage. Christian Heilmann discussed a lot of ideas in his 2010 24Ways article . Have a look at this screencast for a full example along the lines you're thinking.

Note that to cache images in local storage you will need to Base 64 encode them first.

Local storage is a key value store you should prefer to store data objects (json) or single values like strings ore numbers. Don't save the representation layer inside.

You can absolutely use it.

When you configure your cache fot the browser to checks if a file has changed or not it will request a file and the CDN will respond with 304 status code which means the file in the browser cache can be used. However this still requires an HTTP request. You can also use etag or expires so it doesn't do that.

However it could happen that you load external files from sites where you have no control over the header. In that case to not have the http request and 304 response you could save time by using local storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM