CDN Fallback

Thread is closed for posting
1 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 04 Oct 2017 Link to this post


    Telerik Product and Version

    UI for ASP.NET AJAX - all versions since Q3 2009 that support CDN

    Supported Browsers and Platforms

    Browsers supported by UI for ASP.NET AJAX and that support the window.onerror event

    Components/Widgets used (JS frameworks, etc.)

    UI for ASP.NET AJAX - all versions since Q3 2009 that support CDN

    The attached project illustrates one approach to implement a fallback for the Telerik CDN in case the client browser does not have access to the CDN cloud. 

    Below you can find two samples:

    • one holds the full code with detailed explanations and tips so you can tweak it if necessary
    • one holds the minified script to reduce the footprint of the user control

    You use the provided user control by just placing it right after the script manager.

    Key information on the approach:

    • The MS AJAX framework generates an inline <script> tag at the end of the form that contains the $create() statements of the IScriptControl instances on the page, including the Telerik controls. This cannot be avoided. Thus, if the CDN fails these statements will throw errors because the Telerik namespace is not defined.
    • You can use the window.onerror event to capture this error, check if the Telerik object is missing (the try-catch is needed to avoid throwing a new error and breaking this script as well) and if so - invoke a postback that will disable the Telerik CDNs.
    • A hidden field is used to persist this data across postbacks and to ensure an endless loop does not occur (e.g., if other errors are thrown).
    • The stylesheet CDN is much harder to check against, especially without timeouts/intervals. Thus, we make the assumption that if the scripts CDN fails, then the stylesheet CDN will fail as well, and disable it as well. Thus, to have a stylesheet CDN fallback, you must use the script CDN.
    • It is easiest to test this by disabling the network connection on the machine (for example, unplug the network cable). Alternatively, you can use a proxy like Fiddler to route the Telerik CDN.
    • Keep an eye out for other script errors on the page as they can break all scripts on the page and break this approach as well.

    Feel free to share your own versions, improvements or integration examples of such a feature in the comments.

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.