by
tim » Sun Aug 16, 2015 11:43 pm
I think I'm going to have to disagree with you, Graham. Of course, it's your code. You have to write and maintain it. You should do what's comfortable and makes sense to you. Both methods work.
But just for the sake of discussion, I'd say it's better to create well-formed pages server side than it is to create ill-formed pages server side then correct them in the browser using CSS.
The CSS method scatters empty image tags around your webpages then relies on a specific CSS selector with a class name and attribute declaration to hide them on the rendered page. In terms of page efficiency, it's not so clearly a wash, especially if you use Couch's caching feature. It takes time for the browser to process; milliseconds, but the milliseconds quickly add up when it comes to page rendering. And broken pages patched up with CSS don't necessarily play nice with assistive technologies and search engines.
There's more to code efficiency than just number of characters typed, or lines of code. Like you are doing in this case, one tends to repeat patterns of use throughout a code base. Copying and pasting a chunk of code here and there is the same whether there's an if statement in the chunk or not. I can't see how it's preferable to maintain a styling rule that affects the logic and structure of the page instead. If you continue to use the same pattern in different contexts, the problem multiplies.
One of the things that attracted me to Couch initially is that it doesn't boss you around. You can use it where you want, and it doesn't interfere where it's not needed. At first I used Couch pretty sparingly. I already had solutions for many Couch features and saw no reason to change. I used php includes rather than the cms:embed tag, I had my own HTML forms and processing scripts, I didn't even bother using editable regions for most of my static content. The alien and unfamiliar <cms:tag> tags seemed awkward and jarring in my code, and I kind of avoided using them.
But in time I learned to appreciate the power and logic of Couch's feature set, beginning particularly with the cms:if tag. I overcame my prejudices. Couch's tags and logic and preferred solutions became more natural to me. I settled into the Couch and got more comfortable there. I would suggest that your preference for the CSS solution in this case is influenced by that same sense of discomfort and unfamiliarity. But in principle, the server side solution strikes me as being preferable in every way.