<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Perilled &#187; Rails</title>
	<atom:link href="http://perilled.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://perilled.com</link>
	<description>Blog of Erik St. Martin (Ruby Hacker &#38; Psychology Enthusiast)</description>
	<lastBuildDate>Thu, 23 Feb 2012 20:18:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>asset_packager with cache buster &amp; asset_hosts</title>
		<link>http://perilled.com/2009/06/16/asset_packager-with-cache-buster-asset_hosts/</link>
		<comments>http://perilled.com/2009/06/16/asset_packager-with-cache-buster-asset_hosts/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 00:16:00 +0000</pubDate>
		<dc:creator>Erik St. Martin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://perilled.com/?p=8</guid>
		<description><![CDATA[While working on some front end optimizations for a venture of mine I went on the lookout for a better bundling strategy then that provided with the default rails stack. While rails does provide bundling of CSS and Javascript it does not support minification. Which in my opinion is a huge win for site performance, [...]]]></description>
			<content:encoded><![CDATA[<p>While working on some front end optimizations for a venture of mine I went on the lookout for a better bundling strategy then that provided with the default rails stack.</p>
<p>While rails does provide bundling of CSS and Javascript it does not support minification. Which in my opinion is a huge win for site performance, and a less needed feature for this particular project; but a nice to have is the concept of bundles. Specific sets of pages may need the same 3 Javascript files etc. So it would be nice to just keep track of these common bundles and include them as necessary in my layouts and views.</p>
<p>Enter asset_packager. <a href="http://synthesis.sbecker.net/pages/asset_packager">asset_packager</a> is a project created by <a href="http://synthesis.sbecker.net">Scott Becker</a>. Which does exactly what I was looking for. You configure your bundles and the order in which files are placed in the bundle through an easy to configure yml file. And you just run a rake task when deploying to create the bundles. I won&#8217;t go into detail here about how to use it; but feel free to follow the link to the project page here <a href="http://synthesis.sbecker.net/pages/asset_packager">http://synthesis.sbecker.net/pages/asset_packager</a></p>
<p>One thing that I did notice while looking into this project was that it uses <a href="http://www.crockford.com/javascript/jsmin.html">JSMIN</a> ported to ruby. I am personally a fan of <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> so I opted to go with a fork of asset_packager by <a href="http://railsillustrated.com/">Erik Andrejko</a> found here <a href="http://github.com/eandrejko/asset_packager/tree/master">http://github.com/eandrejko/asset_packager/tree/master</a> which uses YUI Compressor for its minification process.</p>
<p>On to the good stuff.</p>
<p>As happy as I was with what I had found, it seemed to still have some inherent problems.</p>
<ol>
<li>When bundling CSS if you are using relative paths, when they get bundled into a file in your base directory your paths will no longer work, so you need to manually modify your CSS files to have absolute paths to your images. Which can often be part of plugin or library that you are making use of like jQuery UI.</li>
<li>If you have implemented far forward expiration dates like you should on your media (my next post will talk about this), your CSS files do not have a cache buster to ensure that when your media is updated the cache is expired</li>
<li>Rails has the concept of an asset_host, it creates a key based on your asset name which will always map to the same domain, and spread the media across asset_hosts by supplying a configuration option in your environment file to help overcome the limit of connections per domain. Well if you design sites the way I do, I have very minimal links to media inside my markup, its all contained in the CSS, so I make very little use of the image_tag helper and therefore little use of the rotating asset_hosts</li>
</ol>
<p>I have created a fork of Erik Andrejko&#8217;s repository for asset_packager and implemented solutions for all of the problems I found above.</p>
<p>During the bundling process it will now determine absolute paths of your assets and use those in the bundled file only. Leaving your originals untouched.</p>
<p>Paths to images are now appended with a cache buster using the same approach as rails, determining the last modified date and appending a timestamp to the url. Now when running your rake task for bundling you can rest assured that new versions of your media will be seen if you have set far forward expiration dates.</p>
<p>If the environment you are running the rake task against has an asset_host set for rails to use asset_packager will pick up on it the same way rails does replacing %d with 0-3, the same asset will always get the same hostname to ensure caching works properly.</p>
<p>While my fork with these changes is of Erik Andrejko&#8217;s repository none of the changes are specific to this fork. They can easily be added to Scott Becker&#8217;s original implementation. <a href="http://github.com/erikstmartin/asset_packager/commit/3881654049a22770e51da9eb0380b61b27aee4c8">The only changes were the addition of a single method, and calls to it from within the bundle method, as well as a change to the rakefile to include the environment so that the method would have access to the rails configuration.</a></p>
<p>my github repo can be found here: <a href="http://github.com/erikstmartin/asset_packager/tree">http://github.com/erikstmartin/asset_packager/tree</a></p>
<p>I&#8217;m open to any comments or questions you may have. Let me know if you find any problems or if you just want to tell me how useful you have found the changes.</p>
<p><strong>update: Erik Andrejko is quick! It appears my changes have already been merged into his branch</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://perilled.com/2009/06/16/asset_packager-with-cache-buster-asset_hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake Spec Errors</title>
		<link>http://perilled.com/2009/04/13/rake-spec-errors/</link>
		<comments>http://perilled.com/2009/04/13/rake-spec-errors/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 04:38:32 +0000</pubDate>
		<dc:creator>Erik St. Martin</dc:creator>
				<category><![CDATA[Rake]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://perilled.com/?p=10</guid>
		<description><![CDATA[I noticed a couple of days ago there are some unexplained errors when running rake spec with the rspec rails gem. That appear to have been there for a while. 3/07/2009 when running script/generate rspec new rake tasks are placed in lib/tasks/rspec.rake if you open this file you will see that line 101 is the [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed a couple of days ago there are some unexplained errors when running rake spec with the rspec rails gem. That appear to have been there for a while. 3/07/2009</p>
<p>when running script/generate rspec new rake tasks are placed in lib/tasks/rspec.rake</p>
<p>if you open this file you will see that line 101 is the offending line</p>
<p><code>::STATS_DIRECTORIES < < %w(Routing\ specs spec/lib) if File.exist?('spec/routing')</code></p>
<p>should be</p>
<p></code><code>::STATS_DIRECTORIES < < %w(Routing\ specs spec/routing) if File.exist?('spec/routing')</code></p>
<p>I sent a message to David Chelimsky so this issue should be resolved in the next release.</code></p>
]]></content:encoded>
			<wfw:commentRss>http://perilled.com/2009/04/13/rake-spec-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

