Adds CDN support to
- Speed: Users will be able to download AngularJS from the closest physical location.
- Caching: CDN is used so widely that potentially your users may not need to download AngularJS and others at all.
- Parallelism: Browsers have a limitation on how many connections can be made to a single host. Using CDN for AngularJS offloads a big one.
This gem offers the following features:
- Can support multiple CDNs, but currently only Google provider is available.
- AngularJS version is automatically detected via angularjs-rails (can be overriden).
- Automatically fallback to angularjs-rails bundled AngularJS when:
- You're on a development environment so that you can work offline.
- The CDN is down or unavailable.
Implications of externalizing AngularJS from
- Updating your JS code won't evict the entire cache in browsers - your code changes more often than AngularJS upgrades, right?
rake assets:precompiletakes less peak memory usage.
- v0.1.4: Clean up and missing specs
- v0.1.3: Be a bit more html_safe
- v0.1.2: Specified license in spec file
- v0.1.0: Initial release
Add this line to your application's Gemfile:
This gem adds methods to generate a script tag to the AngularJS on a CDN of your preference:
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
Then in layout:
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:
It will generate the following for AngularJS on production:
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
config.assets.precompile += %w( angular.js )