0

I am using 3th party CDN servers for my javascript frameworks. But sometime these servers crash and whole my web site can not be rendered. So I thinking to make first look up does file exist on that server if not use local server. Does anyone knows some good solution for it?

1
  • what kind of files must be checked? Commented Nov 12, 2012 at 13:30

2 Answers 2

2

<script> !window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>

Source: http://weblogs.asp.net/jgalloway/archive/2010/01/21/using-cdn-hosted-jquery-with-a-local-fall-back-copy.aspx

You can try to use a function defined in one of the js files loaded by the cdn and if it's not set you can load a local copy of it.

You can see this implemented in many webpages (HTML5 Boilerplate http://html5boilerplate.com/ )

Sign up to request clarification or add additional context in comments.

Comments

1

You could use a scriptloader, like YepNope:

yepnope.js has the capability to do resource fallbacks and still download dependent scripts in parallel with the first. More clearly:

yepnope([{
  load: 'http:/­/ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js',
  complete: function () {
    if (!window.jQuery) {
      yepnope('local/jquery.min.js');
    }
  }
}, {
  load: 'jquery.plugin.js',
  complete: function () {
    jQuery(function () {
      jQuery('div').plugin();
    });
  }
}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.