This might be a site specific issue, but we're running into an issue where www.example.com css/js will reference assets from edit.example.com and vise versa (which ever domain generated the cache first).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cashwilliams’s picture

FileSize
584 bytes

I see why advagg is changing asset urls to absolute full paths, but this is causing the issue. The only quick fix I can see is to add the domain/base_url to the hash key. This however does cause a duplicate of the aggregated files for each domain.

DamienMcKenna’s picture

Status: Active » Needs review
DamienMcKenna’s picture

FileSize
696 bytes

Shouldn't it also prefix the $file string with the $base_url in the static cache? That way if $base_url changes during the execution cycle it'll continue to reference the correct file?

siwinski’s picture

I am still getting cross-domain issues with #3. I am testing with a load balancer and 2 individual nodes. One of the individual nodes keeps getting the load balancer's aggregated files.

siwinski’s picture

This may or may not help your situation, but here is how I solved this issue for my site:

/**
 * Implements hook_advagg_get_css_aggregate_contents_alter()
 */
function mymodule_advagg_get_css_aggregate_contents_alter(&$data, $files, $aggregate_settings) {
  global $base_url, $base_path;

  // Remove protocol and hostname so aggregation can be used cross-protocol and cross-domain
  $data = str_replace($base_url, rtrim($base_path, '/'), $data);
}
mikeytown2’s picture

Pointed these 2 issues here
#2354161: CSS aggregation images url in HTTPS
#2347147: Domain was loaded oer https, but displayed insecure content

In all your cases, what's the value of $_SERVER["HTTPS"]? is it "on"?

Also go to admin/config/development/performance/advagg/info and under "Hooks And Variables Used In Hash" you'll see is_https listed; if that's empty and your on a https site then turning on $_SERVER["HTTPS"] should fix the issue. The http/https switch gets recorded in the 3rd base64-ed hash of the filename as it's a configuration variable. I think the contents_alter trick will modify the 2nd hash as that's a hash of the contents. $base_url might be needed; if it is then using the hash value from admin/config/development/performance/advagg/info might be the ideal way.

cashwilliams’s picture

is_https is properly set to true when loading the site on it editorial/secure domain.
is_https is null when loading the site over http as a anonymous user.

mikeytown2’s picture

Status: Needs review » Fixed
FileSize
27.83 KB

Came up with a couple of solutions for this issue. With this patch AdvAgg will now convert absolute paths to be self references if possible & convert absolute paths to be protocol relative paths.

Completely killing the base_url portion takes care of the domain issue & using protocol relative path for things that don't match the base_url takes care of any http/https issues that might be lurking around.

I also added in the option to include the base_url variable in the hooks hash array as that will cause a different aggregate to be created for every permutation of the base_url variable. I do believe the relative & protocol relative options are better than this though as it allows for the same css/js files to be used on different domains.

Marked this as fixed because it's been committed. Reopen with any bugs you find :)

  • mikeytown2 committed 4b4aabd on 7.x-2.x
    Issue #2353811 by cashwilliams, DamienMcKenna, mikeytown2: Aggregated...

  • mikeytown2 committed 56d6018 on 7.x-2.x
    Issue #2353811 by cashwilliams, DamienMcKenna, mikeytown2: Aggregated...
mikeytown2’s picture

2nd commit was a re-ordering of the admin page; moved more settings to be under the new obscure fieldset.

Status: Fixed » Closed (fixed)

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

therobyouknow’s picture

Has anyone else found solution here in comment #5 https://www.drupal.org/project/advagg/issues/2353811#comment-9276923 from @swinski to be successful? Thank you @swinski I have tried your solution but been unsuccessful so far. Here is how I setup the test and the outcome: https://github.com/NaturalHistoryMuseum/scratchpads2/issues/6519#issueco...

What module did you put your code in @swinski ? When I tried to do the same, make use of your code suggestion by putting it in one of my custom modules, the code did not run, as I checked with both xdebug and some debug code. I followed the hook naming convention etc to ensure my function correctly named. Some info about what I did in that same link above.

I also looked at @mikeytown's subsequent comment here for a solution #8 https://www.drupal.org/project/advagg/issues/2353811#comment-9609605 but saw that this is already in the version of the module I'm running: 7.x-2.8.

So on the basis that the above 2 solutions #5 and #8 didn't work for me, I am now wondering if the latest version of the module will have resolved this, between my version 7.x-2.8 and the latest 7.x-2.35 there are 100s of fixes for various things https://github.com/NaturalHistoryMuseum/scratchpads2/issues/6519#issueco... and I am wondering if among those, this issue here is fixed.

This issue is "Closed (fixed)" - so what actual specific code change makes this issue to be fixed and closed?

therobyouknow’s picture

credit to colleague Ben Scott with this solution:

https://github.com/NaturalHistoryMuseum/scratchpads2/issues/6519#issueco...

The advagg module provides an option to convert absolute URLs to relative, so css/js paths will no longer include www.