Project

cdn_assets

0.0
No commit activity in last 3 years
No release in over 3 years
Quickly and easily include popular CDN assets (e.g. jQuery, Twitter Bootstrap, Font Awesome, etc.) in your Ruby on Rails application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

cdn_assets Gem version

Easily include popular CDN assets (e.g. jQuery, Twitter Bootstrap, Font Awesome, etc.) in your Ruby on Rails application.

This gem can definitely be used as a long-term solution if you're okay with the risks associated with having your assets served by a third party, but it's probably much more suited to those times when you just need to put something together quickly without hassle.

Installation

Add this line to your application's Gemfile:

gem 'cdn_assets'

And then execute:

$ bundle install

Usage

Anywhere in a view file (e.g. the <head> of application.html.erb), use the cdn_asset function to include a single CDN asset. Example:

cdn_asset :jquery, v: '1.10.1', c: :google

Which produces the following output:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

As can be seen, the first argument to the function is the asset name, and the second is a hash of options containing the version (v) and the CDN (c) to serve it from. The options hash can also contain anything you would normally pass as options to a javascript_include_tag or a stylesheet_link_tag.

You can call the function as many times as you want, but if you want to include multiple assets in the same view, then a better way is to pass a hash to the cdn_assets (plural) function. Example:

cdn_assets bootstrap: { v: '2.3.2', c: :cdnjs }, font_awesome: { v: '3.2.1', c: :netdna }

Supported Assets & CDNs

Below is a matrix showing the assets and CDNs currently supported by this gem, ordered alphabetically. Use the exact names listed here as symbols or strings in your code.

cdnjs google jsdelivr microsoft netdna
bootstrap 👍 👍
bootstrap_combined 👍
bootstrap_js 👍 👍 👍
bootstrap_responsive 👍 👍
font_awesome 👍 👍 👍
jquery 👍 👍 👍 👍