VS 2012 Bundles use or not use, that’s the question!

Asked

Viewed 309 times

2

I’m starting in VS 2012 and between the changes appeared the bundles.

I have some doubts:

1 - Is this approach worth using? Why?

2 - The bundles should even stay inside the tag ScriptManager

3 - I can continue referencing the .css and .js old-fashioned?

1 answer

3


1 - Is this approach worth using? Why?

When we talk about website optimization, we need to look at every detail that can decrease processing or traffic, use Bundle allows you to make a grouping of multiple files into a single.

This grouping brings a number of advantages in the economy of bytes trafficked, in addition to providing a fairly efficient way of organizing the project.

2 - The Bundles of even staying inside the tag Scriptmanager

No. You can use the Bundleconfig class located in the App_start folder and add/declare the files you will use, for example:

using System.Web.Optimization;

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        ...

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
            "~/Scripts/modernizr-*"));

        ...
    }
}

Register the Bundle in the method Application_start:

void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    AuthConfig.RegisterOpenAuth();
}

And add the page reference like this:

<asp:PlaceHolder runat="server">        
     <%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>

3 - I can keep referencing . css and . js the old way?

Yes.

References (in English):

  • Thanks. Very enlightening. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.