Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby on Rails plugin - CSS/JS asset bundling in 10 seconds or less!
Ruby JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
MIT-LICENSE
README
init.rb

README

bundle_fu
---------

Each css / js you load causes your site to load slower!  You can speed things up 
exponentially by simply combining all your css/js files into one file each.  

Bundle_fu makes it easy to do.  It's as easy as 1, 2!

----------------------------------------------------
USAGE / INSTALLATION
----------------------------------------------------

=== Step 1 === 
Install this plugin

=== Step 2 ===
Put the following around your stylesheets/javascripts (note it works with any method of including assets!):

  <% bundle do %>
    <%= javascript_include_tag "prototype" %>
    <%= stylesheet_link_tag "basic.css" %>
    <%= calendar_date_select_includes params[:style] %>
    <script src="javascripts/application.js" type="text/javascript"></script>
  <% end %>

That's it!

----------------------------------------------------
GOTCHAS
----------------------------------------------------

  * All content inside of bundle do will be replaced with a single js and css include statement.  Any other content will be lost.  Be sure to only put css / js includes inside of the block.
  * Scripts / stylesheets are detected by parsing the output and looking for include files.  Comments are ignored, so if you comment out a stylesheet like this: 
		  <% bundle do %>
		    <%= javascript_include_tag "prototype" %>
		    <!-- <%= stylesheet_link_tag "basic" %> -->
		    <%= calendar_date_select_includes params[:style] %>
		    <script src="javascripts/application.js" type="text/javascript"></script>
		  <% end %>
    
    The comment will be ignored and the css file will be bundled anyways.  If you need to comment out 
    a css file to perform an ie6 hack, put it outside the bundle block. 
		  <% bundle do %>
		    <%= javascript_include_tag :defaults %>
		    <%= stylesheet_link_tag "basic" %>
		  <% end %>
			<!--[if lt IE 7.]>
		    <%= stylesheet_link_tag "ie6fix" %>
			<![endif]-->    	
    
    (it shouldn't be bundled anyways, since it's conditionally loaded)
  * Relative paths in CSS may be disrupted.
	    If you're css depends on relative paths, they may be disrupted since they will be loaded likely 
	    from a different directory.  You can solve this by changing the directory a bundle is loaded from.

		  <% bundle :css_path => "/stylesheets/", :js_path => "/javascripts/" do %>
		    <%= javascript_include_tag :defaults %>
		    <%= stylesheet_link_tag "basic" %>
		  <% end %>
	    
  * Conditionally loaded css files and javascript files gotcha:
  		Consider the following
			  <% bundle do %>
			    <%= javascript_include_tag :defaults %>
			    <%= stylesheet_link_tag "#{@theme || 'blue'}_color_scheme" %>
			  <% end %>
		    
	    On development, this will work fine.  The bundle.css file will be regenerated everytime the theme changes.  
	    However, on production, this will be effectively ignored, as the content is only regenerated once per
	    server instance.  To remedy this, change the name parameter:
			  <% bundle :name => "bundle_#{@theme || 'blue'}" do %>
			    <%= javascript_include_tag :defaults %>
			    <%= stylesheet_link_tag "#{@theme || 'blue'}_color_scheme" %>
			  <% end %>
  		
  		bundle_fu will generate a different bundle file for each instance of @theme, only once!
  		
Author:
Tim C. Harper - irb(main):001:0> ( 'tim_see_harperATgmail._see_om'.gsub('_see_', 'c').gsub('AT', '@') )

Something went wrong with that request. Please try again.