Reputation: 786
I was wondering if I can have something like
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
and in case it is not available ...how can I load something like
<script src="../localjs/jquery.js"></script>
And same with CSS
I am asking because I work with CDN a lot, and sometimes I'm developing in Localhost and I am not able to connect to the internet and some scripts stop working, I was wondering if I can do this so I don't have to worry about changing them again and again between CDN and local files.
Upvotes: 1
Views: 445
Reputation: 35409
Include the following, right after the opening <body>
tag:
<body>
<script>
if (!jQuery)
document.write('<script src="/local/jquery.js"><\/script>');
</script>
<!-- ... html ... -->
</body>
Upvotes: 2
Reputation: 160833
You could do something like below:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../localjs/jquery.js">\x3C/script>')</script>
Further reading: CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.
Upvotes: 4