-
Notifications
You must be signed in to change notification settings - Fork 137
How to Use Bundling and CDN
The ASP.NET AJAX Control Toolkit has many script and style files that it relies on. This can become a problem because each request takes time to be processed. And most browsers limit the number of simultaneous connections per hostname.
Bundling allows you solve this problem by combing multiple scripts or stylesheets into a single one and thus reduces the number of requests and improves the overall loading time.
With v15.1 release of the ASP.NET AJAX Control Toolkit, we have leveraged the ASP.NET approach to bundling by using the ASP.NET Web Optimization Framework. This framework builds bundles of web application content files located within the project.
Install the AjaxControlToolkit.StaticResources NuGet package. You can install this by right-clicking the project in Solution Explorer and choosing “Manage NuGet packages…” and searching for and installing “AjaxControlToolkit.StaticResources”. Installation of this nuget package makes the following changes to your application:
- All required scripts, styles, and images are added to the project (~/Scripts/AjaxControlToolkit and ~/Content/AjaxControlToolkit folders)
- AjaxControlToolkit config section is added to Web.config
- Script and style bundles are registered in the BundleTable.
Manual changes required:
After installation, please make the following manual changes to your project (these changes are usually made on the master page):
Add a ScriptReference to ScriptManager to register the script bundle:
<asp:ScriptManager runat="server">
<Scripts>
...
<asp:ScriptReference Path="~/Scripts/AjaxControlToolkit/Bundle" />
</Scripts>
</asp:ScriptManager>
Add the Styles.Render expression to the element.
<asp:PlaceHolder runat="server">
<%:System.Web.Optimization.Styles.Render("~/Content/AjaxControlToolkit/Styles/Bundle") %>
</asp:PlaceHolder>
Switch compilation to the release mode in Web.config
<configuration>
<system.web>
<compilation debug="false" ... />
</system.web>
</configuration>
Once bundling is configured then you can verify that it works using the following step:
Open the browser and view the page source code: two links to ASP.NET AJAX Control Toolkit bundles should be rendered instead of links to individual files:
<link href="/Content/AjaxControlToolkit/Styles/Bundle?v=hash" rel="stylesheet"/>
<script src="/Scripts/AjaxControlToolkit/Bundle?v=hash" type="text/javascript"></script>
- remove ScriptReference from ScriptManager
- remove the Style.Render expression from the element
- in the “ajaxControlToolkit” config section (Web.config), set the “renderStyleLinks” attribute to “true”, and the “useStaticResources” attribute to “false”
ASP.NET AJAX Control Toolkit resource files (scripts, styles and images) are also available via Microsoft Ajax Content Delivery Network. The CDN provides better request handling and caching.
Please note that using CDN is not recommended on an Intranet and during development, since servers are closer to you than CDN servers in these cases.
Enabling CDN depends on whether bundling is used or not.
When bundling is turned on, set the System.Web.Optimization.BundleTable.Bundles.UseCdn property to True. This is commonly done in the Application_Start() method in the Global.asax file.
When bundling is turned off, set the ScriptManager EnableCdn attribute to “true”:
<asp:ScriptManager runat="server" EnableCdn="true">
<Scripts>
...
</Scripts>
</asp:ScriptManager>
This content was moved from https://ajaxcontroltoolkit.codeplex.com/documentation to this Documentation wiki. This is now the authoritative location of the AJAX Control Toolkit documentation.
- Step-by-Step Installation Guide
- Upgrading from v7.x and below
- Uninstalling the AJAX Control Toolkit
- Troubleshooting Installer Issues
- Updating the Project from CI Builds
- How to Use Bundling and CDN
- Creating a Custom Localization
- Creating a Custom Control
- Design Standards
Controls:
- Accordion
- AjaxFileUpload
- AreaChart
- AsyncFileUpload
- BarChart
- BubbleChart
- ComboBox
- Editor (deprecated)
- Gravatar
- LineChart
- NoBot
- PieChart
- Rating
- ReorderList
- Seadragon
- TabContainer
- TabPanel
Extenders:
- AlwaysVisibleControl
- Animation
- AutoComplete
- BalloonPopup
- Calendar
- CascadingDropDown
- CollapsiblePanel
- ColorPicker
- ConfirmButton
- DragPanel
- DropDown
- DropShadow
- DynamicPopulate
- FilteredTextBox
- HoverMenu
- HtmlEditor
- ListSearch
- MaskedEdit
- MaskedEditValidator
- ModalPopup
- MultiHandleSlider
- MutuallyExclusiveCheckBox
- NumericUpDown
- PagingBulletedList
- PasswordStrength
- PopupControl
- ResizableControl
- RoundedCorners
- Slider
- SlideShow
- TextBoxWatermark
- ToggleButton
- UpdatePanelAnimation
- ValidatorCallout