Project

js_include

0.0
No commit activity in last 3 years
No release in over 3 years
A Rails extension to ensure single inclusion of JS
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Overview

This Ruby gem patches ActionView to add the js_include method to your views. The difference between js_include and the default javascript_include_tag is that the latter will re-include Javascript that has already been included on the same page. js_include was created to allow for a convenient means of being assured that a single Javascript source file will be included only once, regardless of how many times it may times js_include might have been called on it.

Use case

The primary use case of js_include is in partials. In the case where a partial requires it's own collection of Javascript it, the partial template can easily js_include whichever source files it needs. If the parent template also js_include the same same file, js_include will just do "the right thing"

Usage

To get started, you will need to include the js_include gem in your project. Simply edit your Gemfile to include the line:

gem "js_include", "~> 0.9.5"

Once completed, do not forget to run bundle install, and you are off to the races.

From your views you can now use js_include wherever you previously have used javascript_include_tag.

<%= js_include 'jquery' %>