Can you store JavaScript and CSS files in localStorage to improve the performance of an online web app?

后端 未结 4 1728
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 10:20

I\'m working on a web application, which acts pretty much like a native application for both iOS and Android. However the Javascript files (jQuery + my own) and the css file tog

4条回答
  •  伪装坚强ぢ
    2021-02-04 10:46

    I've also been attempting to get this done without any luck. It seems the only way to do this is the follows:

    • Use AppCache only for images
    • Have all of your CSS and JS inline on the first page
    • Once everything is loaded, have a JS script running to pull each of the scripts into localStorage
    • You can version them through cookies to make sure the user has the most up-to-date copies

    Have a look at http://sunpig.com/martin/archives/2011/05/21/considerations-for-caching-resources-in-localstorage.html for ideas on implementation!

    I'm only halfway through but it's already working much better than depending on the appCache.

    Edit: Keep in mind this is only useful for multi-page apps. If you're building a single page JS app, I don't think it's worth the effort to store back in localStorage. You might as well just inline everything and keep it there for best performance.

提交回复
热议问题