Igor Lankin
Igor Lankin

Reputation: 1486

ASP.NET/MVC Bundler Cache does not work

In an MVC5 project we encounter a problem with caching of the bundled resources (js/css).

According to the mvc docs, by default the bundles should be cached. And it works in other projects. However, here, no matter what configurations, the response headers for our resources are

Cache-Control: no-cache, no-store
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/javascript; charset=utf-8
Date: Wed, 01 Jul 2015 11:22:11 GMT
Expires: -1
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Microsoft-IIS/8.5
Transfer-Encoding: chunked
Vary: Accept-Encoding

I can't figure out where this is coming from as we are not disabling cache anywhere. Any ideas?

Upvotes: 2

Views: 572

Answers (1)

Piotr Czarnecki
Piotr Czarnecki

Reputation: 1688

As I suggested in the comment Igor claimed that in Global.asax there were code for disabling caching:

Response.Cache.SetCacheability(HttpCacheability.NoCache);   
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); 
Response.Cache.SetNoStore();

Igor just to inform you these lines is one of the suggested way to fix 'browser back button' scenario (but as you can see with some cons). Simple scenario steps:

  1. Login to application - looged in user is redirected to the home page
  2. Logout - user redirected to the login page
  3. Click back browser button - User should not be redirected to the home page but with enabled caching it could be an issue.

Please check the back browser button funcionality. If the scenario which I wrote is a problem for you please just use atribute

[OutputCache]

with proper parameters.

Regards Piotr

Upvotes: 4

Related Questions