如何将twitter-bootstrap cdn回退到本地副本 [英] how to fallback twitter-bootstrap cdn to local copy

查看:144
本文介绍了如何将twitter-bootstrap cdn回退到本地副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多发布有关如何通过检查全局变量 JQuery 的存在来将JQuery CDN回退到本地副本的问题。

There are many posts about how to fallback a JQuery CDN to a local copy by checking the existance of the global variable JQuery.

我的问题是,如何对twitter-bootstrap做同样的事情?是否在bootstrap中定义了一个变量,以便我可以检查以确保CDN可用?

My question is , how to do the same to twitter-bootstrap ? Is there a variable defined in bootstrap so that I can check to make sure the CDN is available ?

BTW,我使用 netdna.bootstrapcdn.com 作为我的bootstrap CDN

BTW, I use netdna.bootstrapcdn.com as my bootstrap CDN

推荐答案

我没有看到twitter-bootstrap为此目的暴露的特定变量,他们不会将所有插件附加到jQuery UI的命名空间。你的下一个最好的选择是测试其中一个bootstrap插件。也许是这样的:

I didn't see a specific variable that twitter-bootstrap exposes for this purpose and they don't attach all of their plugins to a namespace a la jQuery UI. Your next best bet is to test for one of the bootstrap plugins. Perhaps something like this:

if(typeof($.fn.modal) === 'undefined') {
    //load bootstrap locally
}

不幸的是,它很脆弱。如果重命名或删除模态插件,则此检查将始终失败。

The unfortunate thing about this is that it is brittle. If the modal plugin is ever renamed or removed this check would always fail.

这篇关于如何将twitter-bootstrap cdn回退到本地副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆