When i enable my BundleTable.EnableOptimizations in my mvc project for my javascript files it doesn't load any of the files. I'm not getting any errors as well. It simply won't load any of my files.

This is my bundle:

bundles.Add(new ScriptBundle("~/Content/javascripts").Include(
                    "~/Content/js/custom.js",
                    "~/Content/js/customizer.js",
                    "~/Content/js/main.js",
                    "~/Content/js/bootstrap.js",
                    "~/Content/js/jquery-ui-min.js",
                    "~/Content/js/bootstrap-switch-min.js"
                    ));

And in my view:

@Scripts.Render("~/Content/javascripts")

All the files do exist, because when i disable the optimizations it works fine again.

有帮助吗?

解决方案

It might be mistaking your virtual path ~/Content/javascripts for a real path. Try this instead.

bundles.Add(new ScriptBundle("~/bundles/javascripts").Include(
                "~/Content/js/custom.js",
                "~/Content/js/customizer.js",
                "~/Content/js/main.js",
                "~/Content/js/bootstrap.js",
                "~/Content/js/jquery-ui-min.js",
                "~/Content/js/bootstrap-switch-min.js"
                ));

And in your view.

@Scripts.Render("~/bundles/javascripts")

其他提示

When you enable bundle Optimization in MVC it uses virtual folder the ~/Bundles/JQuery?v=xxxxx. in my case it was access denied (use F12 tool), because of this virtual folder "bundles" was not allow to access without login. I added bundles path to web config as:

  <location path="bundles">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

hope this helps

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top