Why is #attached library load not working, but drupal_add_library works? This question is specific to D7:
I'm trying to load in jQuery UI modal into the theme. I've put the following in my THEMENAME_preprocess_html:

$variables['page']['content']['#attached']['library'][] = array('system', 'ui.dialog');


This isn't loading the library at all.

DPM-ing the $variables array after the above line shows that it's all added correctly (There's even other stuff in there like, addthis.js):


Direct link: http://i.imgur.com/iTeynMR.png

Obviously all caches were cleared. At this point the console shows an error that dialog is not defined. But as soon as I add this (in the same function, just below the #attached line):

drupal_add_library('system', 'ui.dialog');


then the dialog modal opens and starts playing nicely. Am I doing something wrong with #attached? I'm really puzzled as to why one's working and the other doesn't. Ideally I'd like to use #attached in the cases where the variables array gets cached and the preprocess doesn't get called.
Because the render array has already been rendered before the preprocess functions, '#attached' is not supported in preprocess functions until Drupal 8.

The issue where it was added is https://www.drupal.org/node/2346369

The related Drupal 8 change record is https://www.drupal.org/node/2352319 - this also shows the supported way of doing it in Drupal 7.

Using drupal_add_library() will work, but it will not be cached, so you will take a performance hit. You are better off adding it to the #attached array at a different step in the process.