How to use Bootstrap CDN?

前端 未结 6 977
庸人自扰
庸人自扰 2020-12-23 10:04

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 10:28

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

    
    

    into your HTML. But this doesn't work when you are loading your html from a local file.

    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.

    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/).

    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:

    
    

    Hope this will be userful to someone...

提交回复
热议问题