Mvc 4 bundle and minification - do not receive 304 (does not change) when updating

I am trying to build and minimize the beta version of MVC 4 through System.Web.Optimization . I was hoping the site I use it on will get 304 (Not Modified) when I remove the update.

I thought the src point for my js package, /desktop-js-bundle?v=D33JhbMl9LHkXSPBj1tfRkRI0lHeYVmbSMQqD59bXHg1 (with this version #), was that version # only changed when one of the files in the package on the server was changed . However, every time I delete an update and track the Network tab in Chrome F12 , it makes a request with the same version number and gets a status of 200 .

Why doesn’t he return 304 ?, which will reduce the load and increase the level of a decent amount. Thanks!

+4
source share
2 answers

Why doesn't it return 304?

Because when you press F5 , your browser cache will expire. Basically your test is ruined. You should put links to this package on different pages (using the <script> ). Then you must go to these pages using hyperlinks. Now view the Network tab.

Also make sure that you are in Release mode.


UPDATE:

OK, after I dug up a little more, I found out about it. The HTTP code 200 is indeed sent, which is normal. But the second time the packet is retrieved from the cache.

Here is the first request:

enter image description here

We see that in this case, the bundle occurs from the server with the HTTP cache response headers.

And here is the second request:

enter image description here

In this second screenshot, we can clearly see that the packet is being served from the cache. Note that the entire line is gray. The HTTP 200 status code is fictitious => the client doesn’t even send an HTTP request to the server because it retrieves the packet directly from its cache.

And I can observe the same thing in Google Chrome.

For the first request:

enter image description here

And for the second request:

enter image description here

+3
source

I had the same problem and the problem was in the Microsoft.AspNet.Web.Optimization package. As described here: http://aspnetoptimization.codeplex.com/workitem/127 , versions 1.1.2 - 1.1.3 are affected. After moving to level 1.1.1, it works fine , and 304 returns for immutable resources after the upgrade.

You can do this in the package manager console with the following commands:

 PM> Uninstall-Package "Microsoft.AspNet.Web.Optimization" PM> Install-Package "Microsoft.AspNet.Web.Optimization" -Version 1.1.1 
+1
source

Source: https://habr.com/ru/post/1402645/


All Articles