当CDN服务器关闭时,如何加载Bootstrap CSS的本地副本? [英] How to load local copy of bootstrap css when the cdn server is down?

查看:61
本文介绍了当CDN服务器关闭时,如何加载Bootstrap CSS的本地副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至目前,我正在使用javascript这样的

As of now I'm using like this for javascript

<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script>    $.fn.modal || document.write('<script src="js/bootstrap.min.js">\x3C/script>')</script>

我正在像这样从bootstrapcdn加载bootstrap.css

I'm loading bootstrap.css from bootstrapcdn like this

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">

如果CDN服务器关闭,有人可以告诉我如何加载本地副本吗?

Can someone tell me how to load local copy if the cdn server is down.?

推荐答案

为此,我的解决方案是使用主体顶部的bootstrap隐藏类样式创建一个空div:

My solution for this was to have an empty div using the bootstrap hidden class style at the top of the body:

<div id="bootstrapCssTest" class="hidden"></div>

然后在以后使用Javascript对其进行测试,并在div可见的情况下将其附加到头部:

And then to test it later with Javascript and append it to the head if the div is visible:

    <script type="text/javascript">

    if ($('#bootstrapCssTest').is(':visible') === true) {
        $('<link href="/localcopy/css/bootstrap.css" rel="stylesheet" type="text/css" />').appendTo('head');
    }
</script>

这篇关于当CDN服务器关闭时,如何加载Bootstrap CSS的本地副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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