Loading jQuery and jQuery UI from a Content Delivery Network

The toolkit supports loading jQuery and jQuery UI from a Content Delivery Network (CDN - Goolgle API by defauilt) when loading controls that use them, the ScriptContainer control, the ClientScriptProxy class or ControlResources.LoadjQuery() and ControlResources.LoadjQueryUi() methods.

CDN loading script links look are generated into the page as follows:

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        if (typeof (jQuery) == 'undefined')
            document.write(unescape("%3Cscript src='/WestWindWebToolkitWeb/wwSC.axd?r=Westwind.Web.Controls.Resources.jquery.js' type='text/javascript'%3E%3C/script%3E"));
    </script>  
...
</head>

Note that the generated HTML includes a local fallback URL that uses a WebResource (for jQuery.js) and a local fallback Url (for jQueryUi) to allow for no internet connection. Header injection requires a attribute in order to work.

Enabling CDN Loading
You can control whether CDN loading occurs and where these libraries load from with code in your Application_Start or other 'startup' handler for your Web application. These properties are static so typically they only need to be set once on startup:

// Force jQuery to be loaded off Google Content Network
ControlResources.jQueryLoadMode = JQueryLoadModes.ContentDeliveryNetwork;

// override jquery urls explicitly - you can specify any URL: MS CDN, your own servers etc.
//ControlResources.jQueryCdnUrl = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js";
//ControlResources.jQueryCdnUiUrl = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js";
//ControlResources.jQueryUiLocalFallbackUrl = "~/scripts/jquery-ui.min.js";

Once the above setting has been made all requests to load jQuery, jQuery UI via any of the code based mechanisms will be made using Content Delivery Network.

**jQuery UI has no WebResource in the Westwind.Web library** Note that jQuery UI never loads from WebResources because of its size and additional requirements for related themes so WebResource for jQuery UI always uses a fixed URL that is provided via ControlResources.jQueryUiFLocalFallbackUrl.
*

© West Wind Technologies, 1996-2016 • Updated: 12/19/15
Comment or report problem with topic