Home

Awesome

angularjs-rails-cdn

Gem Version Build Status Dependency Status Code Climate Coverage Status

Adds CDN support to

Serving javascripts and stylesheets from a publicly available CDN has clear benefits:

Features

This gem offers the following features:

Implications of externalizing AngularJS from application.js are:

Changelog:

Installation

Add this line to your application's Gemfile:

gem 'angularjs-rails-cdn'

Usage

This gem adds methods to generate a script tag to the AngularJS on a CDN of your preference: angularjs_include_tag and angularjs_url

If you're using assets pipeline with Rails 3.1+, first remove //= require angular (or other special files if you are using not full version) from application.js.

Then in layout:

= angularjs_include_tag :google
= javascript_include_tag 'application'

Other possible usages:

# To override version
= angularjs_include_tag :google, version: '1.1.5'
# To load additional AngularJS modules
= angularjs_include_tag :google, modules: [:resources,
:cookies]

Note: currently only valid CDN symbols is:

:google

It will generate the following for AngularJS on production:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
window.angular || document.write(unescape('%3Cscript src="/assets/angular-3aaa3fa0b0207a1abcd30555987cd4cc.js" type="text/javascript">%3C/script>'))
//]]>
</script>

on development:

<script src="/assets/angular.js?body=1" type="text/javascript"></script>

If you want to check the production URL, you can pass force: true as an option.

angularjs_include_tag :google, force: true

To fallback to rails assets when CDN is not available, add angular.js in config/environments/production.rb

config.assets.precompile += %w( angular.js )