user13002303
user13002303

Reputation:

Is it just me or is stackpath.bootstrapcdn.com slow?

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

Answers (1)

davidkonrad
davidkonrad

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

  1. If you have users worldwide they will (probably) experience faster load times
  2. You avoid a lot of hits / load on your own server

There is imho two reasons for not using a CDN

  1. You really dont know for sure if a ressource is available, and you dont even know if a certain CDN exists tomorrow at all
  2. Theoretically you can use a CDN to track users. and some CDN's does that.

Upvotes: 1

Related Questions