I would like to distribute the aggregated bundles among several "cookie less" subdomains that I've set up.

I've created a module that lets me specify the available subdomains.

During hook_advagg_filenames_alter one of the subdomains is chosen at random and inserted into the array passed to the hook implementation. However, this information cannot be passed on to do anything meaningful.

Is there a better place to insert such information?

Also, I'd like to use this during advagg_build_css/js_bundle(). This would require to have different files for http and https.

Any suggestions?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeytown2’s picture

I've built advagg with the assumption that the CDN module would be used for things like this. The schema and host get set in advagg_build_uri.

advagg_build_css/js_bundle are fairly simple functions. If you wish to modify what goes in here I would use hook_advagg_css_pre_alter() & hook_advagg_js_pre_alter(). If the cache is getting in the way then disable it:

global $conf;
$conf['advagg_use_full_cache'] = FALSE;

hook_advagg_disable_processor() is the only hook that runs every time; disable the cache in here. You can see an example of this hook in action here #1246816: Create workaround for jquery update ahah form bug when using node clone and a filefield loading jquery.js from googles cdn.

killes@www.drop.org’s picture

Status: Active » Needs review
FileSize
2.05 KB
307 bytes

Thanks for your comment.

I think we are thinking of different things here.

I've developed the module I was talking about, please see the attached file.

Initially, I wanted to use the filename_alter hook, but this proved to be difficult since the bundle information isn't passed on.

Now I am using hook_advagg_css/js_alter and store the information similar to how the compress_js module does it.

This approach relies on two things:

1) a one-line patch to advagg to use file_create_url().

2) Pressflow, or the patch that comes with the CDN module.

It is slighly inelegant since I have to parse the bundler md5 out of the filename in the file_url_alter hook...

mikeytown2’s picture

FileSize
1.16 KB

I would do a advagg_get_file_data(), merge in your data, and then call advagg_set_file_data().

  $subdomains = variable_get('advagg_subdomains', array());
  $key = array_rand($subdomains);
  $data = advagg_get_file_data($bundle_md5);
  $data['advagg_subdomains'] = $subdomains[$key];
  advagg_set_file_data($bundle_md5, data);
...
...
  if (strpos($path, 'advagg_css') !== FALSE || strpos($path, 'advagg_js') !== FALSE ) {
    $url = parse_url($GLOBALS['base_url']);
    $file = explode('/', $path);
    $file = $file[count($file) - 1];
    $bundle_md5 = explode('_', $file);
    $bundle_md5 = $bundle_md5[1];
    $data = advagg_get_file_data($bundle_md5);
    $url['subdomain'] = $data['advagg_subdomains'];
    $path = $url['scheme'] .'://'. $url['subdomain'] .'.'. $url['host'] . base_path() . $url['path'] . $path;
  }

Here's a patch for advagg that I have for you to test out. I would like to keep the default behavior that is found in drupal_get_css if the hook_file_url_alter patch hasn't been applied.

killes@www.drop.org’s picture

Thanks, your approach looks more stable.

The patch to advagg seems to break something, the css files get created but have size 0.

mikeytown2’s picture

hmmm I can't repo that on my test box with the patch. See if your subdomains module is causing issues.

killes@www.drop.org’s picture

I think it's not the module as such, but some issue with the cdn patch. Did you try with or without?

mikeytown2’s picture

With the CDN patch.

killes@www.drop.org’s picture

Strange. I'll debug more tomorrow.

killes@www.drop.org’s picture

It seems as if my subdomain data is ending up in file_save_file() which of course doesn't like an array as input.

mikeytown2’s picture

yep! That is the error.

advagg_subdomains_advagg_css_alter(&$data,
...
  $data = advagg_get_file_data($bundle_md5);
...

I gotta think of better variable names besides data

killes@www.drop.org’s picture

heh, I had even seen that and removed the &. Of course php5 foiled that...

Everything seems to work now, thanks again!

mikeytown2’s picture

Status: Needs review » Reviewed & tested by the community
mikeytown2’s picture

Status: Reviewed & tested by the community » Fixed

committed

mikeytown2’s picture

Nice module :)
http://drupal.org/project/cookieless_subdomain
I'll try to get a stable release out the door sooner rather then later for ya.

Status: Fixed » Closed (fixed)

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