Check if html 5 shim is loaded

让人想犯罪 __ 提交于 2019-12-06 03:20:43

问题


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 ?


回答1:


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



回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/11281888/check-if-html-5-shim-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!