First of, I am using jQuery-1.8.2…
I was wondering how can I load custom scripts from other server and from main server as backup.
Just like loading jquery or jquery tools or jquery ui… and so on.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="<?php echo $siteURL; ?>/js/jquery-1.8.2.min.js"%3E%3C/script%3E'))</script>
I am not really sure how can I do this for custom script… For example for the link below.
<script src="//dvL-den.net/custom/random-script.min.js"></script>
The first code snippet works by detecting if the
jQueryglobal object has been created. That’s all. (It presumes that no other scripts are creating any global variables named ‘jQuery’, but that’s a reasonable — although not infallible — presumption.)You need to do the same — check to see if some unique global variable, object, or property in your custom script exists, and if not, assume the script hasn’t been called. It can be anything, even a bizarre variable like
var window._this_is_a_test = truewhich is set solely for this purpose.