CDN Support – RadControls for ASP.NET AJAX

by ASP.NET AJAX Team | Comments 20

The 2009 Q3 Service Pack 1 landed in your accounts just minutes ago and it holds a great surprise.

Starting with this release you’ll be able to load the control scripts and skins from the Telerik CDN.

You can deploy your applications with CDN support free of charge. That’s right - we cover all hosting expenses for the CDN.

The Telerik CDN is hosted on the Amazon CloudFront service. This is a global content delivery service with edge locations in the US, Europe and Asia.

supersonic

Coming soon to a cloud near you

Why use a CDN?

Using the Content Delivery Network has a number advantages:

  • Reduced latency – requests will be automatically redirected to the nearest server
  • Better use of caching – each resource only needs to be downloaded once
  • Reduced hosting expenses – we host the resources for you so you can pay less

Caching is what a CDN is all about. Say you have a number of applications that all utilize RadGrid. A customer will load the RadGrid scripts just once and then use the cached version until he clears his browser’s cache. Proxies will also aggressively cache these resources.

The resources on the CDN will be served in a gzip-compressed form for all browsers that support it.

When NOT to use a CDN?

You shouldn’t just always use a CDN. Intranet applications in particular are a bad candidate for it. Your Intranet is likely to be a lot faster than any type of CDN. You’ll also lose the ability to run your application without an Internet connection.

You can’t use CDN with interim releases such as internal builds. We’ll upload and maintain files on the CDN only for official releases.

How to enable the Telerik CDN support?

Now to the sweet details. The first requirement is to have both RadScriptManager and RadStyleSheetManager on your page. You can then enable the CDN support globally from the web.config file:

<appSettings> <add key="Telerik.ScriptManager.TelerikCdn" value="Enabled" /> <add key="Telerik.StyleSheetManager.TelerikCdn" value="Enabled" /> </appSettings> 

You can control the setting on per-instance basis as well:

<telerik:RadScriptManager runat="server" ID="RadScriptManager1"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadScriptManager> <telerik:RadStyleSheetManager runat="server" ID="RadStyleSheetManager1"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadStyleSheetManager>

How are end users affected?

The Telerik CDN uses the following host names:

  • http://aspnet-scripts.telerikstatic.com
  • http://aspnet-skins.telerikstatic.com

When a SSL connection is used RadScriptManager and RadStyleSheetManager will fallback to the Amazon S3 service which uses the following hosts:

  • https://telerik-aspnet-scripts.s3.amazonaws.com
  • https://telerik-aspnet-skins.s3.amazonaws.com

Make sure that your visitors have unlimited access to these hosts before enabling the CDN support.

What about the Microsoft CDN?

Microsoft hosts the MS AJAX framework and other ASP.NET scripts on their very own CDN. Using it will further improve the performance of your .NET 3.5 and 4.0 applications. Please, see the recommended settings and notes below.

ASP.NET 4.0 in particular allows you to load everything (including legacy ASP.NET scripts) from their CDN. Please, see this blog post on InfinitiesLoop for more information.

Recommended settings

ASP.NET 2.0

<telerik:RadScriptManager runat="server" ID="RadScriptManager1"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadScriptManager> <telerik:RadStyleSheetManager runat="server" ID="RadStyleSheetManager1"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadStyleSheetManager>

The Telerik resources will be loaded from the CDN, MS AJAX will be served by RadScriptManager.

ASP.NET 3.5

<telerik:RadScriptManager runat="server" ID="RadScriptManager1"> <CdnSettings TelerikCdn="Enabled" /> <Scripts> <asp:ScriptReference Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Name="MicrosoftAjax.js" Path="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js" /> </Scripts> </telerik:RadScriptManager>

Both MS AJAX scripts and Telerik resources will be served from the respective CDNs.

ASP.NET 4.0

<telerik:RadScriptManager runat="server" ID="RadScriptManager1" EnableCdn="true" EnableScriptCombine="false"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadScriptManager> <telerik:RadStyleSheetManager runat="server" ID="RadStyleSheetManager1"> <CdnSettings TelerikCdn="Enabled" /> </telerik:RadStyleSheetManager>

All ASP.NET scripts and Telerik resources are served from the respective CDNs. Note that we need to disable the script combining in this case in order to serve MS AJAX from the Microsoft CDN. This will be fixed in time for the official .NET 4.0 release.

See it in action!

We’ve updated our WebMail demo to use the Telerik CDN as a demonstration. Please, feel free to give it a try.

More details

Please, consult the online help for more details:

RadScriptManager CDN Support

RadStyleSheetManager CDN Support

 

Your feedback is welcome :)

About the author

Iana Tsolova

Iana Tsolova

is Program Manager of Telerik’s ASP.NET AJAX division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.

20 Comments

Terry Smith
Awesome!!!

This is really, really great news. One question though. Will cache headers be returned from the CDN resources as well?
tgmav
What about custom skins created with the Telerik Visual Style Builder?
Steve
Aren't we drastically increasing our http request count if every js\css comes individually on the same subdomain?
Tsvetomir
@Terry - Yes, we're already setting far-future Expires date and all the other headers needed for efficient caching.

@tgmav - We only host the standard skins. If you have a custom skin you can still deploy it on CloudFront or other CDN, but you'll have to take care of setting it up. Which is very easy by the way.

@Steve - We're serving the scripts and skins from different hosts for this very same reason. That means that the resources will be coming from at least three hosts including your server. Still, we're relying on the fact that users with primed caches will have to do a lot less requests in the first place.
Jerry
Is there a failure-roll-over to allow the scripts to be loaded from the hosted site if the client does not have access to the CDN servers due to strict firewall rules?

Tsvetomir Tsonev
We've been thinking about Firewall issues as well, but we don't believe that an integrated automatic detection is the best solution. We prefer the control behavior to be as stable as possible and we want to avoid "automagical" behavior.

Still, this is a valid problem and we want to provide guidance on how this can be implemented as part of the application logic. We're still prototyping some ideas and we'll publish our recommended solution once we're ready.

Phuc
Great News !
I am wondering if it is possible to use the recommended settings for ASP.NET 3.5 in the web.config file to use CDN glabally for MS AJAX resources as well.
Tsvetomir
The answer is no at the moment as script references cannot be configured through web.config. We'll consider implementing this in future releases, but for the moment your best option is a master page or a base class.
Steve
We tested this new feature by adding the two lines to web.config.
The - not so good - results: Telerik scripts are no longer combined and the browser has to download/check a large bunch of individual css/js files. Yes it is coming from Amazon but summing up all those requests we get an overall slower performance on the more complex pages.
Is this on purpose? Was it not possible to propose script combining and CDN?

Tsvetomir
Hi Steve,

The CDN can only serve static resources. This makes dynamic script combining impossible.

This is mostly offset by the fact that resources will not be requested more than once. Your initial page load will be a tad slower, but once the client has the file cached it won't request it again.

This has another, less than obvious, benefit. Say you have one page with RadGrid and another page with RadGrid and RadMenu. If you visit both pages, you'll load the RadGrid scripts only once. If you use script combining you'll load them twice.

The decision on which approach to use should take the application structure into consideration.

I hope this helps.
Paul

 


<
asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />

 

 

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />

 

 

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />

Is there any reason these 3 scripts couldn't be combined into one as an option?

Also is it possible to reference the JQuery one from another CDN (such as Google) as that would be more commonly cached

Thanks.

Paul

 

Tsvetomir
Hi Paul,

The Core.js is not merged with jQuery.js exactly to give you the possibility to load your own instance of jQuery:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" Path="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" />
    </Scripts>
</asp:ScriptManager>

The jQueryInclude.js is not required for the functioning of the controls and its content can be placed directly on the page after RadScriptManager.
Phuc
Hello,

If the CDN option is enabled, should we disable the Web Resources for RadControls (UseEmbeddedScripts  =  false) ? Or is it done automatically ?

Thanks
Tsvetomir
No, EnableEmbeddedScripts should stay on.
Phux
Hello,

I am using 2009 Q3 Service Pack 1with the CDN activated from the web.config file.
I have also enabled the IIS 7 dynamic compression and all the pages are sent compressed to the client. 
But all the files from telerik CDN are served uncompressed. With the same client, I have tested your webmail demo and the CDN files are compressed.

Is there anything sepcial to configure to get compressed file from the CDN ?

Thands
Marijn
This comment might be a bit late, but could you disclose which S3 Region you use for SSL connections?
The reason I ask is that I am about to develop a web application over https solely for the Dutch market.
Also, how long are you planning to leave older versions of the resources around on S3?
Tsvetomir
Hi Marijn,

The S3 bucket for the Telerik CDN is US-based. You might have better results in your scenario if you host the Telerik resources on a server within the country. Alternatively, you can choose a CDN provider that supports SSL (Limelight, Akamai and others).

We provide guidance on how to do this in this help article - http://www.telerik.com/help/aspnet-ajax/cdn-custom-provider.html

I hope this helps.
Basel
I just repeat Phux comment, why compression is not used?

Basel
BTW: i noticed that you mention :The resources on the CDN will be served in a gzip-compressed form for all browsers that support it

but this is not effective yet
Todd
@Basel- Please note that the compression is applied if you load the scripts from the /ajaxz/ path (note the "z" in the path). If you inspect your requests and see that in the path, you should also see that GZIP compression is being applied.

Browsers that do not support compression will load the scripts from /ajax/ (no "z" in the path).

Hope that helps.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by ASP.NET AJAX Team - or - read latest articles in Developer Tools