[英]how to generate headJS fallbacks
How can I properly implement fallback for headJS and Jquery (if the CDN fails to load) within the head load function? 如何在head加载功能内为headJS和Jquery(如果CDN无法加载)正确实现后备?
I cant find anything on the documentation about fallbacks. 我在文档中找不到有关后备的信息。
http://headjs.com/ http://headjs.com/
My code is the following: (right now HeadJS and Jquery are loaded from CDN) 我的代码如下:(现在,HeadJS和Jquery是从CDN加载的)
<script src="//cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js"></script>
<script>
// this loads jquery asyncrounously & in parallel
head.load("//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js", "script1", "script2");
if (head.screen.innerHeight < 800) {
/* code specific to VIEWPORT < 800 */
head.load("{T_THEME_PATH}/footable/js/footable.min.js");
head.ready(function () {
// some callback stuff
$('.footable').footable();
});
}
</script>
Here the answer wit headJS. 这是headJS的答案。 run a test and fallback to something else like this
运行测试并回退到其他类似的东西
head.load({"jquery": "...path to cdn"});
and then 接着
head.ready("jquery", function() {
if (!window.jQuery) {
head.load({"jquery": "...path to fallback"});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.