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

后端 未结 4 1726
没有蜡笔的小新
没有蜡笔的小新 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:31

    It should be possible to get a browser to cache assets like javascript includes (although ultimitely these directives can be over-ridden by the user, probably not something to worry about). See here for a crash-course on caching. In particular see the HTTP header:

    Cache-Control: public
    

    which should force the browser to cache the asset. Not sure if this works across sessions, e.g if the browser is closed and re-opened, but at least only one request will be made when the user first hits your site, and won't be re-requested on subsequent page views.

    Also make sure your javascript includes are minimised, and see here for general tips on speeding things up.

提交回复
热议问题