I have my application in .Net framework 4.It is a Asp.Net Web Application.i need to use Bundle.Config in order to use Bundling feature.
I have read many documents saying that, it is feature in .Net framework 4.5 and that to in Asp.Net MVC Application.
I need to make a bundle for Scripts in aspx pages. Can i include Bundle.Config in my file so that Bundling works.
I have my application in .Net framework 4.It is a Asp.Net Web Application.i need to use Bundle.Config in order to use Bundling feature.
I have read many documents saying that, it is feature in .Net framework 4.5 and that to in Asp.Net MVC Application.
I need to make a bundle for Scripts in aspx pages. Can i include Bundle.Config in my file so that Bundling works.
Share Improve this question asked Jan 8, 2014 at 8:29 SunilSunil 1282 silver badges15 bronze badges3 Answers
Reset to default 12Yes, you can use bundling in ASP 4. Use Nuget Package Manager
to install Microsoft ASP.Net Web Optimization Framework
to your project. Then in global.asax
register the bundles in Application_Start
method. something like this -
var jqueryBundle = new ScriptBundle("~/Scripts/jquery");
jqueryBundle.Include(new string[] {
"~/Scripts/jquery-1.8.3.js",
"~/Scripts/jquery-ui-1.9.1.custom.min.js",
"~/Scripts/jquery-ui-timepicker-addon.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate-additional-methods.js"
});
BundleTable.Bundles.Add(jqueryBundle);
Then in your aspx
page or masterpage
call the bundle-
<%= System.Web.Optimization.Scripts.Render("~/Scripts/jquery") %>
Over couple trial and Reading Bundling i found the solution
Install Web Optimizer framework from NuGet package Manager for the solution include System.Web.Optimization in following file, even in Apsx file.
in Application_StartUp () :
var bundles = BundleTable.Bundles;
bundles.UseCdn = true; //enable CDN support
var jqueryCdnPath = "http://code.jquery./jquery-1.9.1.js";
var jQueryUICdnPath = "http://code.jquery./ui/1.10.3/jquery-ui.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",jqueryCdnPath));
bundles.Add(new ScriptBundle("~/bundles/jqueryui", jQueryUICdnPath));
In Aspx page :
<script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryui")%>" type="text/javascript"></script>
<script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jquery")%>" type="text/javascript"></script>
~/bundles/jqueryui : for UI java script ~/bundles/jquery : for functionality java script.
- Add dll file WebGrease.dll in Reference
Add Bellow code for js and css in global.asax
dynamic solutioncss = new System.Web.Optimization.StyleBundle("~/bundles/solutionDetailCSSBundle"); solutioncss.Include("~/Style.css", new CssRewriteUrlTransform()); solutioncss.Include("~/incs/highslide/highslide.css", new CssRewriteUrlTransform()); solutioncss.Transforms.Add(new CssMinify()); System.Web.Optimization.BundleTable.Bundles.Add(solutioncss);
dynamic HeaderLinkBundle = new System.Web.Optimization.ScriptBundle("~/bundles/HeaderLinkBundle"); HeaderLinkBundle.Include("~/js/jquery.js"); HeaderLinkBundle.Include("~/js/headerlink.js"); HeaderLinkBundle.Transforms.Add(new JsMinify()); System.Web.Optimization.BundleTable.Bundles.Add(HeaderLinkBundle);
System.Web.Optimization.BundleTable.EnableOptimizations = true;
Add this bundle of css and js to aspx page.