VS2012 - Web Forms - Pool Confusion

I created a new ASP.NET Web Forms project through Visual Studio 2012. Unfortunately, the Site.Master file is very confusing by default. (I am posting these questions together because they are very related and contain links to the same code.)

First, I already understand the purpose of linking and minimizing, so there is no need to discuss this. However, I do not understand what happens with the way scripts are included in the main page by default.

Question 1:
Why is the package "~ / bundles / WebFormsJs" created in the BundleConfig.cs file, and yet on the main page each of these individual .js files is displayed one after another in the ScriptManager?

Inside BundleConfig.cs:

bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include( "~/Scripts/WebForms/WebForms.js", "~/Scripts/WebForms/WebUIValidation.js", "~/Scripts/WebForms/MenuStandards.js", "~/Scripts/WebForms/Focus.js", "~/Scripts/WebForms/GridView.js", "~/Scripts/WebForms/DetailsView.js", "~/Scripts/WebForms/TreeView.js", "~/Scripts/WebForms/WebParts.js")); 

Inside Site.Master:

 <body> <form runat="server"> <asp:ScriptManager runat="server"> <Scripts> <%--Framework Scripts--%> <asp:ScriptReference Name="MsAjaxBundle" /> <asp:ScriptReference Name="jquery" /> <asp:ScriptReference Name="jquery.ui.combined" /> <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> <asp:ScriptReference Name="WebFormsBundle" /> <%--Site Scripts--%> </Scripts> </asp:ScriptManager> 

As you can see ... each of the same .js files is separately specified in the ScriptManager. I don’t even see links to the "WebFormsJs" package that was created somewhere outside of BundleConfig.cs. Why has this package ever been created if each of these javascript files is mentioned separately here in ScriptManager?

Question 2:
Why is ScriptManager used this way at all? I was impressed that ScriptManager was necessary for Microsoft Ajax, for example, using UpdatePanels. What is the purpose of using ScriptManager here ... just to register javascript files?

Question 3:
What is the difference in registering javascript files with ScriptManager compared to the top of Site.Master, where the following approach is used instead?

 <%: Scripts.Render("~/bundles/modernizr") %> 

Question 4:
Inside ScriptManager, I also noticed:

  <asp:ScriptReference Name="MsAjaxBundle" /> <asp:ScriptReference Name="jquery" /> <asp:ScriptReference Name="jquery.ui.combined" /> 

... I can at least recognize "MsAjaxBundle" from BundleConfig.cs, but where are jquery and jquery.ui.combined defined? I did a search and found a link to them in packages.config.

 <package id="jQuery" version="1.7.1.1" targetFramework="net45" /> <package id="jQuery.UI.Combined" version="1.8.20.1" targetFramework="net45" /> 

But I do not understand what is happening here. I thought package.config was used for NuGet. Plus ... I don’t even see the path indicated here for the location of these jQuery.js files. They are listed here and are strangely related to a specific version of the .NET Framework (4.5 in my case). Why the javascript resource will be associated with a version of the .NET Framework outside of me.

In any case, question 4 is: how is the "jquery" resource added / used in the ScriptManager? Why can't I see jQuery.js files grouped together in BundleConfig.cs, like all other packages?

Question 5:
Can I remove the following script link from Site.Master if I do not plan to use UpdatePanel and those Microsoft Ajax controls? I'm a little confused why this is still included here by default.

 <asp:ScriptReference Name="MsAjaxBundle" /> 
+49
webforms visual-studio-2012 asp.net-optimization
Sep 05 '12 at 22:13
source share
3 answers

UPDATE: This is a new blog post that also talks more about this: an ASP.NET article

Basically webforms + bundling looks like this because of a bunch of inherited behavior that we could not change in the scriptmanager.

Regarding your specific questions:

  • Basically, this is so that deduplication works correctly, the script manager has a restriction on the source script resources that prevent them from being a script, so they must be mapped to disk, which is then correctly released, since the files are already included in the kit. WebformsBundleJs is a script mapping that is created inside PreAppStart code inside nupkgs ScriptManager. (I agree that this is almost impossible to detect)

  • New 4.5 features, such as unobtrusive validation, require jquery (through the scriptmanager), which is why the script manager was used to ensure that jquery does not appear twice.

  • This will work fine, but it will never be deduplicated using the ScriptManager. So for modernizr this will not be a problem.

  • Jquery packages transfer jquery files to disk in the scripts folder.

  • This link draws in msajaxbundle which contains all ajax scripts, if you don't need / need, I think it can be deleted.

+16
Sep 06
source share

I had more or less the same questions ...

However, on question 4, I have a different opinion.

WebFormsBundle and MsAjaxBundle are Script links that were defined in PreAppStatCode (for example, I cannot find where this file is).

So, I have the feeling that in the same place (ScriptManager.WebForms PreAppStartCode), by default there is another definition for jQuery and jQueryUI Script reference. These links are used in the Script manager.

This process is very important, because in this way you use some important functions, such as CDN, etc. In the jquery definition in PreAppStartCode there is a specific CDN path for this specific link that will be used if you enable EnableCDN in the script manager of the main page (EnableCdn = "true")

0
Jun 06 '13 at 10:21
source share

Just to clarify something from the explanation of the accept answer for Question 1:

The reason for script links for individual web form js files is that local files (such as "~ / Scripts / WebForms / WebForms.js") override the same files that exist on the system. Web.dll (If you reflect System.Web.dll and look in the folder with links, you will find the same .js files).

0
Dec 15 '15 at 18:40
source share



All Articles