I've got a page (menu callback) which serves as a template for an external service. As the HTML of the page is consumed by the external service and rewritten then served from their server, all the CSS and JS paths must be absolute. Elsewhere on my site I use relative paths via AdvAgg, but here I need to rewrite all the link elements to be of the type file, rather than type external.

How can I do this? I have tried doing a hook_css_alter or hook_js_alter and changing type to external and prefixing the data value with my site's base URL but it doesn't seem to be making my AdvAgg aggregate files absolute, their paths stay relative.

Another idea I had was iterating through all the site's CSS files and unsetting the local entries and instead calling drupal_add_js or drupal_add_css but referencing the files as external with an absolute path, but I don't know where I would do this.

I'm using Drupal 7 with CSS and JS aggregation turned on and with the AdvAgg module enabled.

  • I don't know where I would do this. me neither because you didn't tell us your drupal version.
    – No Sssweat
    Commented May 17, 2016 at 7:32
  • 1
    @NoSssweat oops, elementary mistake there on my part. I have revised my question. Commented May 17, 2016 at 7:41

1 Answer 1


I had a look at how the web_widgets module was making CSS/JS paths absolute and it looks like a valid solution is just to alter $GLOBALS['base_path'] to add the URL of my site. An easy way to do this is with url():

  $GLOBALS['base_path'] = url('', array(
    'absolute' => TRUE,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.