We have a problem with the using advagg and cdn modules together as follows.

Our corporate website site is behind an Akamai CDN which proxies to various webservers, of which Drupal is just one of many. So for example www.myco.com/xxx and www.myco.com/yyy come to Drupal but the rest go elsewhere.

We have also implemented separate CDN 1.cms.myco.com that also served through Akamai for commonly served .js, .css from Drupal. This domain has no cookies and can have longer caching both in Akamia and the browser.

The problem is as we migrate content into Drupal it may reference .js files that are located at www.myco.com/aaa which is not in anyway connected to Drupal. When we add these to a module's libraries.yml file with the following properties

{type: external, preprocess: false}

Drupal does not treat it as external and tries to serve it from

1.cms.myco.com and they are not there.

We do not want to keep duplicate copies to get around this (though we have so far).

I think the issue is from advagg.module and the code that follows this comment

// If type is external and starts with http, https, or // but points to
// this host change to file, but move it to the top of the aggregation
// stack.

Is there any chance we could get a new obscure option that would allow is to disable this chunk of code?

Note I have a set of instructions that can duplicate the problem with a vanilla Drupal 8 install and a simple custom module if you want.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gregj00 created an issue. See original summary.

gregj00’s picture

Issue summary: View changes

I am working on a patch for this and will submit shortly.

It adds an obscure option preserve_external and a clause in the if statement to check that before converting the external files to use the cdn.

gregj00’s picture

Priority: Major » Normal
Status: Active » Needs review
FileSize
3.75 KB

Please see the attached patch that adds a feature for this issue.

Status: Needs review » Needs work

The last submitted patch, 3: advagg-handle-external-same-host-js-file-2845990.patch, failed testing.

NickDickinsonWilde’s picture

Status: Needs work » Postponed (maintainer needs more info)
FileSize
20.69 KB

Does disabling these options not fix that for you? (on /admin/config/development/performance/advagg)
fix options

gregj00’s picture

Hey Nick, Disabling that option does fix a local test, did not try yet on test or prod servers where we have this running. But it should as it would keeps it out of that if statement that changes it from external to file But we do lose the benefit of that what that checkbox provides. At this point we do not have anything that "Fix improperly set type" fixes but we could in the future.

Either way I need to figure out what is not passing on the tests before it.

NickDickinsonWilde’s picture

Yeah that sounds good. However, instead of directly under obscure I'd prefer the option is under the rewrite option and disabled if the rewrite is disabled; make sense?

gregj00’s picture

Hey Nick, That does I have it partially complete and will update it here once I finish.

NickDickinsonWilde’s picture

Status: Postponed (maintainer needs more info) » Needs work

great :) thanks

gregj00’s picture

How about this? In SettingsForm.php I could only disable the js_preserve_external checkbox but not uncheck it if checked. with the "states" functionality. If I tried to uncheck it by adding something like this, then when js_fix_type was checked then js_preserve_external would be automatically checked regardless of the prior state.

        'unchecked' => [
          '#edit-js-fix-type' => ['checked' => FALSE],
 

Also note I only added this functionality for Javascript, as code for css does not have the external but points to the same file if statement as the js function does.

gregj00’s picture

There are no differences between patch 11 and patch 10. I am resubmitting same file as 11 because the tests did not run on the previous submission.

mikeytown2’s picture

Status: Needs work » Needs review
NickDickinsonWilde’s picture

Status: Needs review » Fixed

Applied the patch. Thanks :) very much appreciated!

  • NickWilde committed ba34e07 on 8.x-2.x authored by gregj00
    Issue #2845990 by gregj00, NickWilde: External JS hosted by same domain...
mikeytown2’s picture

#2864421-17: Fix external JS type option logic has a better way of detecting the base_url

Status: Fixed » Closed (fixed)

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