Simplify stylesheets on your Rails application
styled_objects is a Rails plugin for simplifying stylesheet management on your application. Instead of having one or more large stylesheets on your public folder, have many. Keep your CSS close to their respective templates. styled_objects will compile them into one file per page. See styled_objects on github
Comments
This is a neat idea. I love the Rail’s communities drive to be better, but I don’t know if this plugin will work for everyone from a performance perspective. It seems like it is just generating more HTTP requests and downloading a larger amount of data on the client’s end.
Let’s say I’m working with a large, complex application, with a 10 “glued” styled_objects (which is fairly conservative, I think). If these are mixed and matched with different page loads, I could easily have two or three dozen versions of my compiled stylsheets. If you figure an average base of 8k zipped, plus your “glued” styles we might average 20k per stylesheet. That adds up to a lot of extra overhead.
A typical approach for a complex app would segment out your stylesheets for different sections of your application - a users stylesheet, an admin stylesheet. Perhaps this behavior could be managed with a gem?
My suggestion: It would be cool if there were a gem that would allow you to segment out your stylesheets in a similar fashion, but let you, pass in a config file of how to allocate those assets based on different sections of your site. For example, let’s say you had three partials with matching stylesheets _partial1, _partial3 and _partial2 spread out among three controllers. What if you could group those controllers in your config file and the gem would compile a stylesheet for all the stylesheet assets needed for that group of controllers.
The would still keep your stylesheets easy to manage across a complex application, but you wouldn’t suffer from the needless http requests numerous versions of cached stylesheets. You might have 2-4 versions instead of a couple dozen.
Just an idea…
-Mario mario - orbitalvoice.com
Post a comment