MVC4 Bundling slow when using Scripts.Render

霸气de小男生 提交于 2019-12-10 03:14:47

问题


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?


回答1:


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 :-)



来源:https://stackoverflow.com/questions/13267189/mvc4-bundling-slow-when-using-scripts-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!