Hacker News new | ask | show | jobs
by michaelchisari 5579 days ago
I mildly disagree that coupling it to the controller makes the best sense. Maybe in MVC that isn't component structured, but even then, you'd probably want more granular control than that.

In Appleseed[1], I mapped CSS component views, and foundations. Foundations are layouts of components, and describe the whole page. Views describe a specific view of a component.

So, basically, if I have a component "example", with a view "list", then I can create a file in the default theme:

  themes/default/styles/components/example/list.css
It will only get loaded into the <head> if the list view of the example component is loaded. I do similar things for the client-side Javascript.

It is good that people are working towards figuring out these patterns, though. The sooner we can move away from the wild west of spaghetti css and javascript, the better.

[1] http://wiki.appleseedproject.org/doku.php?id=developers

2 comments

I would say a big disadvantage of doing it this way is you're serving up different CSS/JS files for each page. The approach in the article lets you separate your CSS out into files based on general "concerns" that make sense to your developers, while being able to use an asset packaging tool like Jammit (or even mod_pagespeed) to package them into one large CSS file that can then be cached by the browser, ISP proxies, and your CDN sitewide.
I would say a big disadvantage of doing it this way is you're serving up different CSS/JS files for each page.

You don't have to, though. You can put everything into a single global css file, and be done with it.

And I haven't implemented it, but I can immediately see easy ways to package it all up into single files that can be easily cached.

It's easier to consolidate the files programmatically after they've been logically separated, than to logically separate out of a monolithic location.

I agree. If you change the names of your controllers, or need the same css in a different controller, you have to make css changes.

This can be a pain. Better to decouple your css from the backend.