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:


92 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. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
    5. 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. Ecorptrainings.com provides ASP.NET in hyderabad with best faculties on real time projects. We give the best online trainingamong the ASP.NET in Hyderabad. Classroom Training in Hyderabad India

    ReplyDelete
  4. 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

  5. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    top workday studio online training

    ReplyDelete
  6. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. devops online training

    ReplyDelete
  7. 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
  8. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    top sailpoint online training

    ReplyDelete
  9. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    microservices online training
    best microservices online training
    top microservices online training

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

    ReplyDelete
  11. 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
  12. 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
  13. Am really impressed about this blog because this blog is very easy to learn and understand clearly.This blog is very useful for the college students and researchers to take a good notes in good manner,I gained many unknown information.


    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  14. Thanks for provide great informatics and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete
  15. 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
  16. We provide best Selenium training in Bangalore, automation testing with live projects. Cucumber, Java Selenium and Software Testing Training in Bangalore.
    Online selenium training in India - KRN Informatix is a leading Selenium Training Institute in Bangalore offering extensive Selenium Training.
    Selenium corporate training
    Automation Testing Training in Marathahalli
    Selenium realtime training with projects
    Best Selenium Training in Bangalore
    Selenium Software Training in Bangalore
    Manual testing training in bangalore

    ReplyDelete
  17. Thanks for this amazing blog, visit Ogen Infosystem for creative web design and development services at an affordable price.
    Website Designing Company in Delhi

    ReplyDelete
  18. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    blockchain online training
    best blockchain online training
    top blockchain online training

    ReplyDelete
  19. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    best tibco sportfire online training

    ReplyDelete
  20. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    top tibco sportfire online training

    ReplyDelete
  21. Water bodies are the main source of transportation for international freight forwarding. Due to this, sea freight company in Delhi,
    visit
    Freight Forwarder in Vietnam
    Shipping Company In India

    ReplyDelete
  22. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    tibco sportfire online training

    ReplyDelete
  23. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    tibco sportfire online training

    ReplyDelete
  24. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    python online training

    ReplyDelete
  25. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    blueprism online training

    ReplyDelete
  26. 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
  27. Thank you for sharing wonderful information with us to get some idea about it.
    Mulesoft Self Learning
    Mulesoft Online Training in India

    ReplyDelete
  28. 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
  29. Great article! It is really helpful for my research. Do post and share more such wonderful content and keep updating.
    Informatica Cloud Training
    SAP Hybris Training
    AWS‌ ‌Data‌ ‌Engineering‌ Training

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

    ReplyDelete
  31. Thanks 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
  32. Thanks 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
  33. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website mulesoft online training
    best mulesoft online training
    top mulesoft online training

    ReplyDelete
  34. You’re so interesting! I don’t believe I’ve truly read something like this before. So great to find someone with genuine thoughts on this issue. Really.. many thanks for starting this up. This website is something that’s needed on the internet, someone with some originality!

    CBSE Schools In Ahmedabad
    CBSE Schools In Surat
    CBSE Schools In Rajkot
    CBSE Schools In Visakhapatnam
    CBSE Schools In Kangra
    CBSE Schools In Shimla
    CBSE Schools In Jammu
    CBSE Schools In Solan
    CBSE Schools In Mangalore
    CBSE Schools In Mysore

    ReplyDelete
  35. Say, you got a nice article post.Really thank you! Really Great.
    salesforce training
    salesforce online training

    ReplyDelete
  36. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website mulesoft online training
    best mulesoft online training
    top mulesoft online training

    ReplyDelete
  37. thanks for sharing nice blog https://duckcreektraining.com/

    ReplyDelete
  38. 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
  39. 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
  40. Thanks 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
  41. You can Also download cracked softwares for windows and mac's.Check my web page: idm serial key

    ReplyDelete
  42. 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
  43. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al

    ReplyDelete
  44. 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
  45. This comment has been removed by the author.

    ReplyDelete
  46. There will be best course in Hyderabad, duck creek policy program,duck creek can earn a salary 130000 per annum.it is useful to students career in the field you have interest visit my website link.thanks youhttps://duckcreektraining.com/

    ReplyDelete
  47. Great blog,Thank you

    Intrested Guys once check it our blog once,

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

    ReplyDelete
  49. 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
  50. An awesome blog for the freshers. Thanks for posting this information.
    ServiceNow Training
    ServiceNow Online Training

    ReplyDelete