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?
<script> !window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>
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/ )
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();
});
}
}]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.