Tuesday, September 4, 2012

Using ASP.NET Bundling and Minification with Web Forms

Bundling and Minification is a new feature of ASP.NET 4.
Learn more from this tutorial http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification.

It has been promoted as part of ASP.NET MVC 4, but actually does not depend on MVC stack and may by used within any ASP.NET application including ASP.NET Web Forms.

When you start a new ASP.NET MVC 4 application using Visual Studio template, it sets up all what you need to start using this feature, but if you have an existing ASP.NET application (even not MVC), you have to complete following steps to make it works with your app.


Adding reference to System.Web.Optimization library

System.Web.Optimization is not a part of .NET 4 framework. But it is provisioned by NuGet package manager.

Open NuGet and search for Microsoft.AspNet.Web.Optimization package.



As you may see, it depends on two other packages, but you don't have to worry, NuGet will manage all dependencies and will install them as well.


Now you may see a few new references added to your project:  Antlr3.Runtime, Microsoft.Web.Infrastructure, System.Web.Optimization and WebGrease.


All new referenced are set to be copied to /bin folder (Copy Local = true in property window), so they are deployed to server with your application. No need to mess with GAC :).

Register bundle


All the rest is according to tutorial. Register bundles with Application_Start:

Include bundle in the page

In my scenario I use Web Forms and have an *.aspx with a master page. To include the bundle in the page, it is simply enough to add one line of code within head tag:


Runing application

Now you can run the application. Depending on debug settings in Web.config you will get either all scripts (included in the bundle) included separately in the page (debug="true") for debugging purpose, or single all-in-one minified script include

CSS bundling

In the same manner you can use CSS bundling

Register StyleBundle:


Include in the page:


63 comments:

  1. hi, im really struggling with this and wondering if you can help. im doing this on a vs2010 website in WEBFORMS and iv got the package from nuget. here is my code in my global.asax:

    void Application_Start(object sender, EventArgs e)
    {
    // Code that runs on application startup

    System.Web.Optimization.BundleTable.Bundles.Add(new System.Web.Optimization.ScriptBundle("~/bundles/js").Include("~/scripts/jquery.bxSlider.js"));

    }

    and my script:

    <%: System.Web.Optimization.Scripts.Render("~/bundles/js") %>

    But the bundle script tag doesn't even render... any ideas?

    ReplyDelete
    Replies
    1. Do you have a repro? You may send me a sample project for debugging to igor.israel@gmail.com

      Delete
    2. thanks igor, problem is its a large corporate site! however does it help in saying its a website rather than a web project, can that make a difference?

      Delete
    3. No difference between web site and web project.

      Delete
    4. Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download Now

      >>>>> Download Full

      Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download LINK

      >>>>> Download Now

      Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download Full

      >>>>> Download LINK TU

      Delete
  2. hanks for sharing this. We really want to find a good website design company. Our business could really use one. What would you suggest?
    Asp.net development company Delhi

    ReplyDelete
  3. Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”.
    asp net development in ukraine

    ReplyDelete
  4. Very informative and creative content. This concept is a good way to enhance the knowledge.thanks for sharing
    SQL Azure Online Training
    Azure SQL Training
    SQL Azure Training

    ReplyDelete
  5. Thanks, Experience with various technologies and businesses this is generally helpful selenium online training

    ReplyDelete
  6. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore


    ReplyDelete
  7. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening.


    Full Stack Course Chennai
    Full Stack Training in Bangalore

    Full Stack Course in Bangalore

    Full Stack Training in Hyderabad

    Full Stack Course in Hyderabad

    Full Stack Training

    Full Stack Course

    Full Stack Online Training

    Full Stack Online Course



    ReplyDelete
  8. Really nice post. Thank you for sharing amazing information.Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Java Training in Chennai

    Java Training in Bangalore

    Java Training in Hyderabad

    Java Training
    Java Training in Coimbatore

    ReplyDelete
  9. Welcome to Softcore Technologies, The Best Training Center for your requirement of Software Programming Courses, Computer Basics, MS Office, Accounting Courses like Tally, Tuition for all subjects starting from 10th Standard (SSC) up to Post Graduation like MBA.

    Best MS Office Training in Hyderabad
    Best Spoken English Training in Hyderabad

    ReplyDelete
  10. Hello, I'm so glad I found your blog, I actually found you by mistake, when I was looking on Google for something else, Anyways, I'm here now and would just like to say thank you for a fantastic post.
    ASP.net Development Company

    ReplyDelete
  11. Really nice blog.And I suggest you the best online training to Become QA Certified Professional QA Training Online

    ReplyDelete
  12. How to Deal with Search in Outlook Not Working?

    Outlook users mostly have the query related to search in Outlook not working. If you are also facing the same issue then you need to restart your Outlook device properly. One can also think to repair Outlook program by using the Microsoft Inbuilt Repair tool. This tool will help you to deal with the issue smoothly without facing any other error.

    How to Silence Outlook Notifications on iPhone?

    Check out the steps properly and know how to silence Outlook notifications on iPhone, then follow the steps properly. For Gmail users, you need to click on the gear icon towards the upper right of the Gmail window. Now, choose the settings ink and then tap to mail notifications off under the Desktop notifications section. Lastly, tap to save to smoothly silence Outlook notifications on iPhone devices. Follow the steps properly to know about Outlook notifications on your iPhone device.

    Why is My Yahoo Mail Not Working?

    The possibility for users facing why is my Yahoo mail not working issue is because of technical glitches in your account. To deal with it, check for the underneath steps. For this, proceed to iPad or iPhone and then open Safari. Now, proceed to Yahoo homepage or choose the link and i.e.http://mail.yahoo.com/. Lastly, you need to login to your account and then you can send or read the emails properly. Even if everything is working properly then also you need to check account settings as there might be chances those issues lies here only.

    How to Perform Bellsouth Email Setup?

    To perform Bellsouth email setup, open Android and then open Bellsouth in your Gmail account. After that, select the menu bar option and press the drop down next to name and select the add account button. After that, you need to choose either Bellsouth settings, you can either choose POP3 settings or choose IMAP settings for configuring the email account. After that, enter password and tap on next button. Verify the POP server and type att.net for inbound server and 995 as port number. After that, enter Att.net for SMTP settings and 465 as secured security layer. These are the steps to perform Bellsouth email setup process.

    How to Recall Email Outlook App iPhone?

    If you are an iPhone user and want to know about the steps to smoothly recall email Outlook app iPhone then here’s what you have to do. For this, open web browser on iPhone and proceed to Outlook.com. Now, log into your Outlook account by using correct credentials. Now, choose sent items folder and open email that you want to recall. Locate the message tab in open window with your email. Click on recall this message under move option. Lastly, you need to replace the sent email with the new one or delete the unread email by clicking on OK.

    ReplyDelete
  13. How to Enable Java in Chrome in Windows 10?

    Check out the guide properly and know about the steps to know how to enable Java in Chrome in Windows 10. If you are using Windows and want to enable Java in Chrome browser then use the Java control panel to do it. For this, open Java control panel and choose the security tab. At the top, check to enable Java content in the browser. Now, click to apply and choose OK to confirm the changes. Lastly, you need to restart Google Chrome to enable the changes. These are the steps to follow to enable Java in Chrome in Windows 10 device.


    ReplyDelete
  14. hanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website Workday HCM Online Training
    best Workday HCM Online Training
    top Workday HCM Online Training

    ReplyDelete
  15. Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download Now

    >>>>> Download Full

    Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download LINK

    >>>>> Download Now

    Igor Zelmanovich'S Blog: Using Asp.Net Bundling And Minification With Web Forms >>>>> Download Full

    >>>>> Download LINK Bu

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Great blog,Thank you

    Intrested Guys once check it our blog once,

    ReplyDelete
  18. If you are looking for get some new software so i will help you so much.
    IDM Crack

    ReplyDelete
  19. I am very happy to read this article. Thanks for giving us Amazing info. Fantastic post.
    Thanks For Sharing such an informative article, Im taking your feed also, Thanks.

    ReplyDelete
  20. An awesome blog for the freshers. Thanks for posting this information.Artificial Intelligence Training in Hyderabad

    ReplyDelete
  21. wordpress web design company in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!

    ReplyDelete
  22. thank you for sharing information www.engeng.in

    ReplyDelete
  23. it was very useful blog. thank you for sharing this article. visit: Asp.Net Certification Online

    ReplyDelete
  24. Thanks for sharing this informative article on Using ASP.NET Bundling and Minification with Web Forms. If you want to ASP.Net Development Company for your project. Please visit us.

    ReplyDelete
  25. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. 고양출장샵Great workk

    ReplyDelete
  26. "Great article, felt good after reading, worth it.
    i would like to read more from you.
    keep posting more.
    also follow Propmtengineeringcourseinhyderabad"

    ReplyDelete
  27. "Great article, felt good after reading, worth it.
    i would like to read more from you.
    keep posting more.
    also follow Mern Stack course in hyderabad"

    ReplyDelete