What's new? | Help | Directory | Sign in
Google
bundle-fu
Ruby on Rails plugin - CSS/JS asset bundling in 10 seconds or less!
  
  
  
    
Search
for
Updated Oct 31, 2007 by timcharper
Labels: Featured
FAQ  

Q: I have a few different views that include different sets of stylesheets. How do I accommodate that?

Use the :name parameter. For example:

  # in layouts/application.rhtml
  <% bundle do %>
    <%= javascript_include_tag :defaults %>
    <%= stylesheet_link_tag "basic" %>
  <% end %>

  # in layouts/admin.rhtml
  <% bundle :name => "admin_bundle" do %>
    <%= javascript_include_tag :defaults %>
    <%= stylesheet_link_tag "admin" %>
    <%= stylesheet_link_tag "basic" %>
  <% end %>

Q: I need to debug my JS and CSS, and having it bundled makes it VERY difficult to do!

Just tack on ?bundle_fu=false on any page's URL and it will bypass bundling.

This setting is stored in your user session and will not affect other users of the site. It will stay bypassed until you lose your session.

Q: How does bundle_fu handle yield blocks? wbsmith83

First, bundle_fu renders the content from the block using capture(&block). Then, it parses the rendered content & looks for js/css includes. It uses this list to build the bundle.

Bundle_fu also watches the content from the block for changes in development mode. If a change is made to the content, it will automatically trigger a regeneration of the bundle

Q: Bundle_fu is breaking my css image references. What's wrong?

There were a few issues with the relative URL rewriter in the CSS bundler. All that were reported have been resolved. Please update to the latest version of bundle_fu. If you still have problems, try the mailing list.

GOTCHAS

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)
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!

Instead, you'll need to include each javascript file as normal.

Comment by chuck.bergeron, Oct 29, 2007

Sweet, I think I'm gonna give this a try!

Comment by wiseleyb, Jan 24, 2008

I don't know if this will help anyone but here's a post of how I got bundle_fu working with dynamically generated (then cached) style sheets. I put is a few lines of code in the plugin to go into "bundle_fu=false" mode if files it's trying to combing/compress are missing.

http://mudabone.com/aietc/?p=775

Comment by jonathan.otto, Mar 09, 2008

doesn't work when using the facebooker (facebook.com API) plugin by chad fowler. it uses the tunneled URLs instead of the localhost URL.

Comment by hsiao.anthony, Mar 10, 2008

Is it possible that bundle fu bundles files on every new pageload before caching it?

I'm observing, that there seems to be some 3-4 second delay after calling my site everytime i use bundle fu!

i'd be surprised if that was the case, but u never know...


Sign in to add a comment