0

I'm using following code to bundle my web application scripts, but it does not generate bundled script

   Bundle bundle = new Bundle("~/miniscripts/");
        bundle.Include(
          "~"+  Paths.Scripts.AdminSkin.js.old_browsers_js,
          "~"+  Paths.Scripts.AdminSkin.js.site_js,
          "~"+  Paths.Scripts.AdminSkin.js.list_js,
          "~"+  Paths.Scripts.AdminSkin.js.jquery_accessibleList_js,
          "~"+  Paths.Scripts.AdminSkin.js.jquery_tip_js,
          "~"+  Paths.Scripts.highchart.highstock_src_js,
          "~"+  Paths.Scripts.highchart.modules.exporting_js,
          "~"+  Paths.Scripts.calendar.calendar_js,
          "~"+  Paths.Scripts.calendar.calendar_setup_js,
          "~"+  Paths.Scripts.AdminSkin.js.live_control_js,
          "~"+  Paths.Scripts.linq_js_ver_3_0_1_beta2.linq_js,
          "~"+  Paths.Scripts.moment.moment_min_js
            );

        BundleTable.Bundles.Add(bundle);

What i'm missing? Thanks.

3 Answers 3

2

So assuming you are using the 1.0.0 package, you probably want to be using

new ScriptBundle("~/miniscripts/"); 

Otherwise your Bundle is not doing any minification, its just bundling all the script files together. Then in your page, you will need to add:

Scripts.Render("~/miniscripts");

For the bundle reference to get rendered out. You should also check out the tutorial here: Optimization Tutorial

Sign up to request clarification or add additional context in comments.

Comments

1

I presume you are using the online bundle and minification version.

First you have to add JsMinify when creating the bundle so asp.net knows how to minifiy your files

Bundle bundle = new Bundle("~/miniscript", typeof(JsMinify));

And then you have to add a script reference to your page

<script src="<%: Url.Content("~/miniscript") %>" type="text/javascript"></script> 

1 Comment

Bundle bundle = new Bundle("~/miniscript", typeof(JsMinify)); is deprecated and in AspNet.Web.Optimization [link]nuget.org/packages/Microsoft.AspNet.Web.Optimization optimization version we just provide virtualPath.
1

I found solution, i dont know why Scripts.Render("~/miniscripts/") does not renders scripts. I've wrapped it with Response.Write and the problem solved.

  Response.Write(Scripts.Render("~/miniscripts/"));

1 Comment

Scripts.Render returns you an IHtmlString, you can just do this as well: <%: Scripts.Render("~/miniscripts/") %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.