Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Bundling slow when using Scripts.Render

My asp.net MVC4 web project is running very slowly when serving a simple page that renders bundled scripts. However, when I use a 'hardcoded' script tag on the page with the source attribute of the virtual bundle path then performance is much better:

@Scripts.Render("~/bundles/scripts")                            ~ 4 seconds

vs

<script src='@Scripts.Url("~/bundles/scripts")'></script>       < 1 second

My BundleConfig.cs has no special configuration, this is exactly as it appears:

bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
    "~/Scripts/jquery-1.7.2.min.js",
    "~/Scripts/jquery.validate.min.js",
    "~/Scripts/jquery.validate.unobtrusive.js",
    "~/Scripts/jquery-ui-1.9.0.custom.min.js",
    "~/Scripts/bootstrap.min.js",
    "~/Scripts/bootstrap-modal.js",
    "~/Scripts/bootstrap-dropdown.js",
    "~/Scripts/bootstrap-tooltip.js",
    "~/Scripts/bootstrap-typeahead.js",
    "~/Scripts/bootstrap-transition.js",
    "~/Scripts/bootstrap-popover.js"));

My web.config is even configured to optimize in Debug but I have tried running in Release mode and still get the same result:

<compilation optimizeCompilations="true" debug="false" targetFramework="4.0" />

Any ideas why Scripts.Render is so slow?

like image 842
Nick Avatar asked Nov 07 '12 09:11

Nick


1 Answers

The problem was with the outdated package I had installed. A simple Update-Package in package manager console and I went from

<package id="Microsoft.AspNet.Web.Optimization"
    version="1.0.0-beta2" targetFramework="net40" />

to

<package id="Microsoft.AspNet.Web.Optimization"
    version="1.0.0" targetFramework="net40" />

Now Scripts.Render() is peforming much better :-)

like image 125
Nick Avatar answered Nov 30 '22 20:11

Nick