Search code examples
cssruby-on-railstwitter-bootstrapcdn

Bootstrap-sass Gem v.s. CDN


Various Ruby on Rails tutorials encourage the instillation of the bootstrap-sass gem. Why is this a convention rather than point to a CDN?

I've included in header of my app:

  <!-- BOOTSTRAP CSS 3.3.5 CDN: --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

And in the footer:

  <!-- BOOTSTRAP JS 3.3.5 CDN --><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script>

Assuming I am always working from a development box that is connected to the internet: What is the reasoning behind using the bootstrap gem rather than just pointing to a CDN? Isn't it always faster to point to a CDN where a client is likely to have the file already cached?


Solution

  • The likely reason that Rails' tutorials suggest the bootstrap-sass gem is just a matter of convenience; as Rails' developers we're used to adding a line to our Gemfile to integrate 3rd party libraries.

    There are added benefits to the gem: after you do a bundle install you won't need an internet connection to load your development environment's assets (no need to connect to an external CDN). Also you can use SASS to override Bootstrap mixin variables and customize the framework.

    These benefits aside, if you aren't customizing Bootstrap there is no need to use the boostrap-sass gem in production. In fact your argument about clients possibly already having CDN hosted versions of common JS/CSS frameworks is certainly valid.

    Short answer: don't think of the boostrap-sass gem as a convention. It's a good starting point for customization but if no customization is needed it is perfectly reasonable to go with a CDN.