My theme CSS uses relative paths, but Advagg or another module seems to be rewriting them to absolute paths. Core aggregation uses relative paths Our CSS authored in the theme uses relative paths for all references to assets
But the CSS aggregated/processed by Advagg has absolute paths where the authored CSS uses relative paths


I can't see any Advagg settings where I am asking it to convert relative paths to absolute

When Advagg is disabled, the CSS aggregated by Drupal core noes not have any absolute paths, instead the relative paths from the authored CSS are used
If I enable Advagg but enable the advagg_convert_absolute_to_relative_path setting then relative paths are used, but doing this would cause problems elsewhere on the site where some CSS is used that requires absolute paths. I'd rather Advagg left our relative paths alone, rather than seemed to convert them to absolute paths, and then back to relative paths.
I have a custom module on the site that alters the base URL to make links/URLs absolute for a small subset of the site (which is consumed and displayed on an external domain). This seems like a potential cause, but disabling this module does not resolve the issue.


A potential cause of the issue?

I have a module that uses hook_url_outbound_alter() to make URLs on some pages absolute by modifying the base URL:

/**
 * Implements hook_url_outbound_alter().
 */
function site_absolute_paths_url_outbound_alter(&amp;$path, &amp;$options, $original_path) {
  if (drupal_static('_is_absolute_path_requiring_callback')) {
    $options['base_url'] = _site_absolute_paths_url_modified_base();
    $options['absolute'] = TRUE;
  }
}


This seems like it could be a candidate for causing the issue, but the problem persists even when the changes to the options array in this function are commented out.

I'm not sure how else to debug this? I suspect it is not an issue with Advagg, but something else on this site that is interacting badly with Advagg. That said, it is odd that the aggregated CSS produced by Drupal core has the correct paths rather than the absolute paths.

If the advagg_convert_absolute_to_relative_path setting seems to resolve the issue, does that suggest that something 'upstream' of Advagg is adding the absolute paths? But isn't adding them when the core aggregation process is run? 

Things I have tried

A breakpoint in the first line of advagg_file_create_url() gives "/" as the value for $aggregate_settings['variables']['base_path']. This is what I would expect to be working OK.

global $base_url;
echo $base_url;


In /devel/php gives http://my-site.drupal.dev

Variables used in Advagg hash

Array
(
    [variables] =&gt; Array
        (
            [advagg_gzip] =&gt; 1
            [is_https] =&gt; 
            [advagg_global_counter] =&gt; 10
            [base_path] =&gt; /
            [advagg_ie_css_selector_limiter] =&gt; 1
            [advagg_ie_css_selector_limiter_value] =&gt; 3500
            [advagg_scripts_scope_anywhere] =&gt; 
            [advagg_devel] =&gt; 
            [advagg_convert_absolute_to_relative_path] =&gt; 0
            [advagg_convert_absolute_to_protocol_relative_path] =&gt; 0
            [advagg_force_https_path] =&gt; 0
        )
)


Is this an intended feature of Advagg? This line seems to suggest so:

// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
$contents = preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', '_drupal_build_css_path', $contents);
This is an intended feature of AdvAgg, see Mike (one of AdvAgg maintainer)'s issue on Drupal.org where a 'do not convert' option has been raised as a feature request.