[development] An alternative to common thinking in 5->6 migration

Michael Favia michael at favias.org
Mon Mar 9 17:19:13 UTC 2009


Nancy Wichmann wrote:
>
> In moving modules from 5.x to 6.x it is commonly suggested to move our 
> “drupal_add_css” (and _js/) /into hook_init. Ceratinly I did this in 
> nearly all my modules because it was the common suggestion. However, 
> now that I’m making a big change in one and having problems with the 
> CSS, it dawned on me that this suggestion adds the CSS files to 
> **every** page, not just the ones we were targeting. It finally dawned 
> on me that I have hook_help that only fires on the pages I need to CSS 
> on, so I moved the “drupal_add_css” into hook_help, which to me makes 
> a lot more sense because now my CSS is only applied to those pages for 
> which it is intended. What do others think of this? Are there pitfalls 
> I may not have covered?
>
You clicked "reply" on an email deep inside another thread to make your 
most recent post to the list. Most of us view our email in a threaded 
mail reader to follow discussions and this puts your new question WAY at 
the bottom of this existing (and seemingly interminable) discussion 
where it wont get the attention it deserves. Please dont reply to an 
email to compose a new message to the list. Instead just "compose one" 
from scratch so we can all see it :).

To answer your question, with "css munging" drupal_add_css doesn't 
result in an additional page hit for the new css file (because they are 
combined into 1) and I normally suggest including it because the small 
bandwidth penalty on page load #1 is normally outweighed by the latency 
+ bandwidth on the following page loads where it has t be dynamically 
loaded. if you dont use css munging then you approach has some validity 
i suppose but id be hesitant to put it in the help section and instead 
makes sure it is added when and where needed by your actual theme code 
so that it isnt a maintenance issue.

-mf


More information about the development mailing list