Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

On an MVC site, I organize by controller. There's one general file for generic cross-site stuff (header/footer, etc.), supplemented by another CSS file that shares the markup for all controller-specific pages.

This gives a max of two css files per page. For the landing page I compress the generic file along with the controller-specific css file for the default page into a single file. This speeds up the loading process while preventing too much bloat. Since the other pages are usually hit after the landing page they require only a single extra download. Any reset code can be included in there as well, although maintained as a separate file.

I doubt this approach is ideal when it comes to organizing things, but it's fairly fast when it comes to development. I design by including css in style="" and then refactoring the markup into classes once the design is complete. Saves a lot of back and forth while getting things lined up.



I also organize styles by controller/action in my Rails projects. This trick from "The Rails 3 Way" is great for assigning the correct classes to the page:

Using Haml:

  %body(class="#{controller.controller_name} #{controller.action_name}")
Using Erb:

  <body class ='<%= "#{controller.controller_name} #{controller.action_name}"%>'>




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: