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.

RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
r.zarei
  • 1,261
  • 15
  • 35

3 Answers3

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

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
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> 
Erwin
  • 4,757
  • 3
  • 31
  • 41
  • Bundle bundle = new Bundle("~/miniscript", typeof(JsMinify)); is deprecated and in AspNet.Web.Optimization [link]http://nuget.org/packages/Microsoft.AspNet.Web.Optimization optimization version we just provide virtualPath. – r.zarei Aug 24 '12 at 08:09
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/"));
r.zarei
  • 1,261
  • 15
  • 35
  • 2
    Scripts.Render returns you an IHtmlString, you can just do this as well: <%: Scripts.Render("~/miniscripts/") %> – Hao Kung Aug 24 '12 at 18:49