7

We hit a performance issue recently that highlighted something that I need to confirm.

When you include a bundle like this:

@Scripts.Render("~/jquery)

This appears to be running through (identified using dotTrace, and seen it running through this):

Microsoft.Ajax.Utilities.MinifyJavascript()

for every single request to both the page that has the include, and also the call to the script itself.

I appreciate that in a real world scenario, there will only be 1 hit to the script as the client will cache it. however, it seems inefficient to say the least.

The question is, is this expected behavior, as if it isn't, I'd like to fix it (so any suggestions), but if it is, we can pre-minify the scripts.

UPDATE

So, even if I change the compilation mode to debug, it's still firing the minify method. It outputs the individual urls, but still trys to minify it.

However, if remove all the references to the render methods, it doesn't try to minify anything, and runs rapidly, doesn't balloon the app pool, and doesn't max the CPU on the web server.

Martin
  • 2,180
  • 4
  • 21
  • 41
  • I believe, it does run for every request which is very inefficient. It's recommended that you minify javascript during build phase and include reference to minify files. Bottom line is avoid only minimization. – Saleem Mar 19 '16 at 00:32
  • 2
    See if [this helps](http://stackoverflow.com/a/21314979/304683) - bundling/minification occurs on startup/app recycle, file changes. So _first request_ will run, stored in cache with a file dependency. Hth – EdSF Mar 19 '16 at 01:16
  • The System.Web.Optimization libraries are definitely cache-aware. A quick test with logging inside a bundle config routine also demonstrates this. However, there *are* conditions to the caching. I'd suggest stepping through the source. – Tim M. Mar 19 '16 at 02:59
  • @TimMedora can you tell me how to turn logging on? happy to accept that as a the answer. – Martin Mar 23 '16 at 14:20
  • @Martin, it doesn't appear that there is any logging built into the bundler. I just added a call to my custom application log inside my BundleConfig class to see when it was called. Use the log of your choice, or even just `File.AppendAllText()` to dump to a text file. It's also worth noting that the bundler performs server caching *and* sets an HTTP cache header for the browser (as you noted in your question). – Tim M. Mar 23 '16 at 16:21

0 Answers0