Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load local copy of bootstrap css when the cdn server is down?

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>

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">

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

like image 332
PrivateUser Avatar asked Jan 03 '13 15:01

PrivateUser


People also ask

Is it better to use CDN or local Bootstrap?

CDNs deliver faster loading speeds for readers. Because this content is readily available, it is pushed to users faster than would be the case in a local website server.

How do I connect Bootstrap locally?

Under the folder, copy the extracted files downloaded from bootstrap. Under the head tag of the HTML file, the CSS needs to be linked. The jQuery downloaded should also be copied under the JS file. Make sure that under the project file, the downloaded files and HTML page must be present in that folder.

Does Bootstrap use CDN?

In Bootstrap's case, the main Bootstrap javascript and stylesheet files are being served over a CDN network. By default, Bootstrap recommends using Stackpath's CDN network which already powers over 8 million websites across the globe.


1 Answers

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>

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>
like image 123
Al Stevens Avatar answered Oct 24 '22 19:10

Al Stevens