Question

I'm trying out MVC 4 Beta's bundling and minification thru System.Web.Optimization. I was hoping that the site I'm using it for would receive a 304 (Not Modified) when I hit refresh.

I thought the point of the src to my js bundle, /desktop-js-bundle?v=D33JhbMl9LHkXSPBj1tfRkRI0lHeYVmbSMQqD59bXHg1 (with that version #), was that the version # changed only when one of the files in the bundle on the server was modified. Yet, every time I hit refresh and monitor the Network tab in Chrome's F12, it makes a request with that same version number and gets a 200 status.

Why doesn't it just return 304?, which would decrease the load and increase perf a decent amount. Thanks!

Was it helpful?

Solution

Why doesn't it just return 304?

Because when you hit F5 you expire the cache of your browser. Basically your test is flawed. You should put links to this bundle in different pages (using the <script> tag). Then you should navigate to those pages using hyperlinks. Now observe the Network tab.

Also make sure you are running in Release mode.


UPDATE:

OK, after digging a little more here's what I found out. The 200 HTTP status code is indeed always sent which is normal. But the second time the bundle is fetched from the cache.

Here's the first request:

enter image description here

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

And here's the second request:

enter image description here

We can clearly see in this second screenshot that the bundle is served from the cache. Notice how the entire line is grayed. The HTTP 200 status code is fictional => the client doesn't even send an HTTP request to the server as it retrieves the bundle 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

OTHER TIPS

I had the same issue and the problem was with Microsoft.AspNet.Web.Optimization package. As described here: http://aspnetoptimization.codeplex.com/workitem/127, versions 1.1.2 - 1.1.3 are affected. After downgrade to 1.1.1 it works fine and 304 is returned for non-changed resources after refresh.

You can do it in Package Manager Console with following commands:

PM> Uninstall-Package "Microsoft.AspNet.Web.Optimization"
PM> Install-Package "Microsoft.AspNet.Web.Optimization" -Version 1.1.1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top