5

I profiled my ASP.NET MVC application and I saw strange a function calls.

You can see it on image

enter image description here

Always when mvc render layout we invoke system.web.optimization.scripts.render which invoke JsMinify.Process and Minifier.MinifyJavaScript, but I thought what minification should be one time on the start app.

Am I right?

Maybe must I set some settings for optimization it?

Conditions:

  • localhost
  • release
  • BundleTable.EnableOptimizations = true;
2
  • Do you know if this happens with the Release configuration as well? Commented Jun 18, 2014 at 11:07
  • I verified it only in localhost with Release config. Commented Jun 18, 2014 at 11:58

1 Answer 1

3
+100

Great Question!

Intuitively, you are right, minification of assets should be performed on application Startup. You assume that assets are delivered identically to all browsers. But Microsoft believes that much of JS and CSS is browser specific.

If you check asp.net site's reference on ASP.NET 4.5 Bundling and Minification, they specifically state:

Bundling and minification in ASP.NET 4.5 is performed at runtime, so that the process can identify the user agent (for example IE, Mozilla, etc) , and thus, improve the compression by targeting the user browser (for instance, removing stuff that is Mozilla specific when the request comes from IE).

:


What about caching?

Bundling isn't as obtuse as a profiled would have you think. If you look up MVC 4 Bundling and Minification reference, they point out:

Bundle Caching

Bundles set the HTTP Expires Header one year from when the bundle is created. If you navigate to a previously viewed page, Fiddler shows IE does not make a conditional request for the bundle, that is, there are no HTTP GET requests from IE for the bundles and no HTTP 304 responses from the server.

This is far more information than you need, but the message is that, JSMinify has a check for relevant cached minified assets.

When you factor in further that we already use minified version of our assets (eg jquery.min.js, jquery-ui.min.js), you can appreciate that .Net minification is a supplemental process.

Why does Minification of all types have to happen

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Why not create caching for browsers version on server?
@Mediator, I'm sure the cache is stored on the server. If you're asking why the server doesn't automatically create and cache every conceivable version of the cached minifications and bundle them, I can't be certain, but I suspect it's because there are too many potential versions of browsers to take into account. Such a job is probably too expensive to except as needed.
I looking through the source code and found settings for IE browsers =(. Thank you for answer. I will search solution for caching on an server for different versions browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.