0

I have a .NET MVC 5 website that is hosted as a Windows Azure Website. The site has several large JavaScript files that I would like to cache to the client. I would like the client to only download the JavaScript files on the first load and if the file is updated (cache for infinite length of time). It would be nice if the cache persisted through a re-publish of the website as long as the JavaScript file didn't change.

Is this something that is configured in the MVC project or at the Azure Portal? How do I make it happen? How can I verify that it is actually caching?

Currently I bundle the JavaScript files (into several bundles) in the App_Start\BundleConfig.cs file, for example:

bundles.Add(new ScriptBundle("~/bundles/CustomerPortal").Include("~/Scripts/CustomerPortal.js"));

I then add the script to my view like so:

@Scripts.Render("~/bundles/CustomerPortal")

I am willing to host the JavaScript files elsewhere or in a different method if that is the best way to accomplish this.

user1304444
  • 1,713
  • 3
  • 21
  • 38
  • 1
    Bundle by default should set cache headers to 1 year. See this http://stackoverflow.com/questions/14374656/mvc-bundle-client-caching – Chandermani Feb 03 '14 at 07:47
  • Okay, according to that as long as I'm bundling the files I should be fine...do you know a good way to test this and make certain it's caching correctly? – user1304444 Feb 03 '14 at 08:06
  • I see in my Chrome Developer Tools that it's getting an http 304 code, so I believe that means that it is caching...Thanks. I guess this was easier than I thought :) – user1304444 Feb 03 '14 at 08:22
  • you can use CDN to deliver your JS files too. – Thiago Custodio Feb 03 '14 at 16:54

0 Answers0