Can I use Bundling [Bundle.Config] in .net 4 Asp.Net web Application

I have my application in .Net framework 4. This is Asp.Net Web Application. I need to use Bundle.Config to use the Bundling function.

I read a lot of documents saying that this is a feature in the .Net framework 4.5 and in the ASP.NET MVC application.

I need to create a package for scripts on aspx pages. Can I include Bundle.Config in my file for Bundling to work.

+4
source share
3 answers

, ASP.net 4. Nuget Package Manager Microsoft ASP.Net Web Optimization Framework . global.asax Application_Start. - -

    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);

aspx masterpage -

    <%= System.Web.Optimization.Scripts.Render("~/Scripts/jquery") %>
+11

Bundling

Web Optimizer NuGet , System.Web.Optimization , Apsx.

Application_StartUp():

 var bundles = BundleTable.Bundles;
 bundles.UseCdn = true;   //enable CDN support
 var jqueryCdnPath = "http://code.jquery.com/jquery-1.9.1.js";
 var jQueryUICdnPath = "http://code.jquery.com/ui/1.10.3/jquery-ui.js";
 bundles.Add(new ScriptBundle("~/bundles/jquery",jqueryCdnPath)); 
 bundles.Add(new ScriptBundle("~/bundles/jqueryui", jQueryUICdnPath)); 

Aspx:

  <script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryui")%>" type="text/javascript"></script>
  <script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jquery")%>" type="text/javascript"></script>

~/bundles/jqueryui: UI java script ~/bundles/jquery: java script.

+3
  • dll WebGrease.dll
  • Bellow js css global.asax

    dynamic solutioncss = new System.Web.Optimization.StyleBundle( "~/bundles/solutionDetailCSSBundle" ); solutioncss.Include( "~/Style.css", CssRewriteUrlTransform()); solutioncss.Include( "~/incs/highslide/highslide.css", CssRewriteUrlTransform()); solutioncss.Transforms.Add( CssMinify()); System.Web.Optimization.BundleTable.Bundles.Add(solutioncss);

    HeaderLinkBundle = System.Web.Optimization.ScriptBundle( "~/bundles/HeaderLinkBundle" ); HeaderLinkBundle.Include( "~/JS/jquery.js" ); HeaderLinkBundle.Include( "~/JS/headerlink.js" ); HeaderLinkBundle.Transforms.Add( JsMinify()); System.Web.Optimization.BundleTable.Bundles.Add(HeaderLinkBundle);

    System.Web.Optimization.BundleTable.EnableOptimizations = true;

  • css js aspx.

0
source

All Articles