Question

We generally check if jQuery is loaded from CDN or not and fallback to local version if it didnt.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>

I am using twitter bootstrap, and it loads the html 5 shim from the googlecode copy.

<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>

Is there any way I can fallback to local version if it does not load from googlecode

Or am I doing something wrong. Shouldnt be I checking this ?

Was it helpful?

Solution

<script>window.html5 || document.write('<script src="js/libs/your-local-version.js"><\/script>')</script>

OTHER TIPS

I wouldn't bother falling back with the jQuery (long discussion and can of worms I'd prefer not to open), but that's up to you.

I do think that loading the html5.js from googlecode is going to cause you more problems though, and you should host it locally. Why? Because you're referencing code directly out of the trunk of an SVN tree. That code can/will change on you, which will put your work into an untested state. You could reference a specific revision from Googlecode... or really, just host it yourself.

Host the shiv locally, there are many issues using it from Google (not least the DNS look up etc) for more see - http://zoompf.com/blog/2012/05/html5shiv-and-serving-content-from-code-repositories

As for that jQuery callback code I wouldn't bother, the user will think the page is broken long before the callback fires.

If you let me know the URL of your page I'll demonstrate.

When using html5shim, i would recommend loading it locally in the first place. On their website they have recently changed the wording to make you download the file instead of hotlink it from GitHub, which could host untested code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top