Loading CSS and JS by attaching it to render arrays would solve issues with CSS/JS not loading for cached content, improve performance, alterability, etc.

drupal_add_* will also be remove from Drupal 8 (or will only be available internally), so this will help Privatemsg be more future proof. See #1839338: [meta] Remove drupal_set_*() drupal_add_*() in favour of #attached/response for out-of-band stuff.

Drupal 7 introduced #attached for CSS, JS and some other things so that assets which are needed by a specific element can be properly cached along with its parent element. If you use drupal_add_*() and your code doesn't run (because it's cached), then your CSS won't be added to the page.

CommentFileSizeAuthor
#1 attach-css-and-js-2034237-1.patch5.53 KBDevin Carlson
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

Assigned: Unassigned » Devin Carlson
Status: Active » Needs review
Issue tags: +commonslove
FileSize
5.53 KB

A patch to #attach Privatemsg CSS and JS where possible.

ptmkenny’s picture

Status: Needs review » Reviewed & tested by the community

I applied this patch to my site and confirmed that the CSS is loaded properly. It's working on my local Apache server and also Nginx.

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, committed and pushed to 7.x-2.x. Small behavior change with the templates, so not backporting.

Automatically closed -- issue fixed for 2 weeks with no activity.