BlueFox
BlueFox

Reputation: 950

What's the best way to utilize jQuery-UI theme on CDN with local fallback?

Is there anyway to load jQuery-UI theme from CDN, but with local fallback? Similar to the javascript fall-back outline here? Google Hosted CDN with fall back

Upvotes: 7

Views: 1196

Answers (1)

Sindre Sorhus
Sindre Sorhus

Reputation: 63487

I would recommend using the resource loader yepnope:

yepnope([{
  load: 'http:/­/ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js',
  complete: function () {
    if ( !window.jQuery ) {
      yepnope('local/jquery.min.js');
    }
  }
}, {
  load: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js',
  complete: function () {
    if ( !window.jQuery.ui ) {
      yepnope('local/jquery-ui.min.js');
    }
  }
}]);

This will first try to load jQuery with local fallback, then load jQUery UI with local fallback.

Upvotes: 4

Related Questions