Search code examples
htmlmodel-view-controllerapplication-cache

Using application cache for storing CSS and Javascript files in MVC web application


I'm using a lot of frameworks in my website (Knockout, bootstrap, jquery, jquery ui etc) which is causing it to load slow. Is it a good practice to store these javascript files (ex knockout.js) and associated CSS files(ex bootstrap.css) in Application cache. I looked in my browser's application cache and most of them store sprites, yet to come across JS caching


Solution

  • using applicationCache won't improve the load time for your application, that's what cache headers are for. Best practice here is to

    1. concatenate and compress all your assets
    2. change the filenames of the assets, for example add a hash based on their contents, so app.js becomes app.abc456.js
    3. Set cache headers to cache these assets for ever. As the file names change each time, you won't have any problems with it.

    "The applicationCache is a douchebag": http://alistapart.com/article/application-cache-is-a-douchebag

    Unless you have to make your app work offline, trust me, it's not worth it.