Conditionally load JS based on whether or not a field has data? I'd like to load a javascript file only if a specific field has data. Can this be done with a preprocess function in template.php? Something like:

if this field is not empty
  add the js to the page footer
else do nothing


Is there a more efficient way?
If a field within a specific content type has some content, load some javascript, if there's nothing in the field, do nothing.

function THEME_NAME_preprocess_page(&amp;$variables) {
  if(isset($variables['node']) &amp;&amp; $variables['node']-&gt;type == "CONTENT_TYPE") {
    if(!empty($variables['node']-&gt;FIELD_NAME)) {
      drupal_add_js(drupal_get_path('theme', 'THEME_NAME') . 'PATH-TO-JS.js', array('type' =&gt; 'file', 'scope' =&gt; 'footer'));

    }
  }
}