如何使用Bootstrap CDN? [英] How to use Bootstrap CDN?

查看:234
本文介绍了如何使用Bootstrap CDN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Bootstrap上使用CDN来提高我的网站的性能。然而,当引用CSS直接它工作,而使用CDN不。

I'm trying to use a CDN on Bootstrap to increase performance to my website. However when referencing the CSS directly it works whereas using the CDN doesn't.

我将如何解决这个问题 - 我的代码是附加的。 ?

How would I go about resolving this- my code is attached bolow. ?

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

<html>
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Matt's Homepage</a>
<ul class="nav">
  <li class="active"><a href="#">Home</a></li>
  <li><a href="http://www.akkatracker.com">Blog</a></li>
  <li><a href="http://www.twitter.com">Twitter</a></li>
</ul>
</div>
</div>
<div class="btn"><a href="http://www.akkatracker.com">Click Here to Visit my Blog</a>  
</div>              
</html>


推荐答案

正如其他人提到的,使用CDN通常是容易添加:

As others have mentioned, using a CDN is usually as easy as adding:

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"
      rel="stylesheet">

原因是缺少协议。当使用CDN时,通常不要指定协议,因此您的浏览器将使用http或https,取决于用于获取您的html的协议。

The reason is the missing protocol. When using a CDN, it's usually a good idea not to specify the protocol, so that your browser will use either http or https depending on the protocol used to get your html in the first place.

这很重要,因为如果您的服务器使用https,最好是所有引用使用https,以避免浏览器(特别是IExplorer)抱怨混合内容。另一方面,对CDN使用无协议URL更易于缓存( http://encosia.com/cripple-the-google-cdns-caching-with-a-single-character/ )。

This is important because if your server is using https, it is better to have all references using https to avoid browsers (specially IExplorer) complaining about mixing content. On the other hand, using a protocol-less URL for CDN is more cache friendly (http://encosia.com/cripple-the-google-cdns-caching-with-a-single-character/).

不幸的是,如果协议是 file:// ,则无协议URL是一个坏主意。因此,如果您要创建将从磁盘加载的私有HTML,则应添加协议并使用CDN,如下所示:

Unfortunately, a protocol-less URL is a bad idea if the protocol is file://. So if you are creating a private HTML that will be loaded from disk, then you should add the protocol and use the CDN like this:

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"
      rel="stylesheet">

希望这对某人是有用的...

Hope this will be userful to someone...

这篇关于如何使用Bootstrap CDN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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