In our ASP.NET MVC 4 web application, our BundleConfig.cs includes the following:
bundles.Add(new ScriptBundle(\"~/bundles/jquery\").Include(
I used Identity2 then Scripts didn't load for anonymous user then I add this code in webconfig and Sloved.
<location path="bundles">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Whenever I set debug="off" in my web.config and run my mvc4 application i would end up with ...
<script src="/bundles/jquery?v=<some long string>"></script>
in my html code and a JavaScript error
Expected ';'
There were 2 ways to get rid of the javascript error
BundleTable.EnableOptimizations = false
in BundleConfig.cs OR
By adding following code of line in bundle to config it works for me
bundles.IgnoreList.Clear();
Follow the link for more explanation
add to your global file this action.
protected void Application_Start() {
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
I ran into the same problem, and I'm not sure why, but it turned out to be that the script link generated by Scripts.Render did not have a .js extension. Because it also does not have a Type attribute the browser was just unable to use it (chrome and firefox).
To resolve this, I changed my bundle configuration to generate compiled files with a js extension, e.g.
var coreScripts = new ScriptBundle("~/bundles/coreAssets.js")
.Include("~/scripts/jquery.js");
var coreStyles = new StyleBundle("~/bundles/coreStyles.css")
.Include("~/css/bootstrap.css");
Notice in new StyleBundle(...
instead of saying ~/bundles/someBundle
, I am saying ~/bundlers/someBundle.js
or ~/bundles/someStyles.css
..
This causes the link generated in the src attribute to have .js or .css on it when optimizations are enabled, as such the browsers know based on the file extension what mime/type to use on the get request and everything works.
If I take off the extension, everything breaks. That's because @Scripts and @Styles doesn't render all the necessary attributes to understand a src to a file with no extension.
For me, the fix was to upgrade the version of System.Web.Optimization to 1.1.0.0 When I was at version 1.0.0.0 it would never resolve a .map file in a subdirectory (i.e. correctly minify and bundle scripts in a subdirectory)