Reputation:
I'm using bootstrap 4.4.1 (the latest) and am using stackpath.bootstrapcdn.com. It appears that loading my webpages is slow.
Does anyone else encounter it?
Should I just download the css and refer to it locally?
Upvotes: 1
Views: 1812
Reputation: 85538
You can do both. If you have trouble with a CDN or for some other reason need a fallback, you can test if the CSS is loaded for example this way:
<script>
setTimeout(function() {
let loaded = false
for (let s in document.styleSheets) {
if (document.styleSheets[s].href &&
document.styleSheets[s].href.indexOf('bootstrap.min.css')) loaded = true
}
if (!loaded) {
let link = document.createElement('link')
link.href = 'path/to/fallback/bootstrap.min.css'
link.rel = 'stylesheet'
document.head.appendChild(link)
}
}, 500)
</script>
If bootstrap.min.css
is not loaded after 500ms a new <link href="...>
pointing to a local file will be inserted to the <head>
section of the document..
There is imho two major reasons for using a CDN
There is imho two reasons for not using a CDN
Upvotes: 1