[RESOLVED]MVC Bundling & Minification Problem

Hi, I have bundled my JS files as follows in BundleConfig.cs

bundles.Add(new ScriptBundle("~/bundles/js").Include(
               "~/js/jquery/jquery.min.js",
               "~/js/jquery/jquery.mousewheel.js",
               "~/js/jquery/jquery.widget.min.js",
               "~/js/metro.min.js",
               "~/js/prettify/prettify.js",
               "~/js/load-metro.js",
               "~/js/docs.js",
               "~/js/github.info.js"));

In my Layout I have following in head section:

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

I have a view studentdetials.cshtm in student folder which is not rendering as expected.

In the browser error console I get following 404 – not found error:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1568/Student/js/metro.min.js?_=1413550048924

metro.min.js is not inside the student folder but "JS" folder which is in root of the project directory, however my view is searching it inside the student/js/ folder.

Please let me know what I am missing.

Thanks & Regards

Hi Siteslayer,

I have faced similar issue. Actually during bundling, framework manages js files.

In release mode, you will getting this error but not in debug mode, if i understood the problem correctly.

I am getting this problem in debug mode.

Hi siteslayer,

Thanks for your post.

 You can   Use the F12 Developer Tools to Debug JavaScript Errors.

Bundling and minification is enabled or disabled by setting the value of the debug  attribute in the

compilation Element

 in the Web.config file. In the following XML,debug is  set to true so bundling and minification is disabled.

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

To enable bundling and minification, set the debug value to  "false".

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
    BundleTable.EnableOptimizations = true;
}

Hope this can be helpful.

Best Regards,

Eileen

Eileen ni – MSFT

Hi siteslayer,

Thanks for your post.

 You can   Use the F12 Developer Tools to Debug JavaScript Errors.

Bundling and minification is enabled or disabled by setting the value of the debug  attribute in the

compilation Element

 in the Web.config file. In the following XML,debug is  set to true so bundling and minification is disabled.

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

To enable bundling and minification, set the debug value to  "false".

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
    BundleTable.EnableOptimizations = true;
}

Hope this can be helpful.

Best Regards,

Eileen

Thanks a lot Eileen, that solved the problem. 

Leave a Reply