how I deal with split javascript and css
Posted in Ruby Projects at 11:41PM on 02/02/2009

A lot of rails guys like their plugins and magic helpers and junk, but I've never been a fan.  I prefer to write full HTML & use simple methods that are easy to understand 8 months later when you look back at the code. I've seen a lot of weird methods for splitting CSS & JS files for layouts, but I think my way is one of the simplest.  

I like things clean and consistent.  If I have CSS that applies to only one part of one page, then I'll split the CSS into a file just for that purpose.  I do the same thing with javascript for unobtrusive JS.  So, let's say I have a 'new' and 'edit' action, which also needs a custom CSS file.  I would do something like this:

You can easily see which JS & CSS applies to each action, so you can just grab & edit those ones instead of digging through some giant file that has everything in it. 

Comments
(will not be displayed)