bundling script files in web application with asp.net optimization framework
-
28-06-2021 - |
Question
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.
Solution 3
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/"));
OTHER TIPS
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
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>