0

We have a Drupal 8 site using S3 file system integrated via the S3 File System module.

The aggregated CSS and JS are uploading on S3, however I am not seeing any configuration to serve compressed files.

Can someone suggest a way or any configuration that I am missing?

2
  • 1
    S3 doesn't support gzip - if you search for s3 gzip you'll find a bunch of articles explaining how to gzip before pushing up to the service. I'm not sure if there's an existing solution in the wild for Drupal, my best guess would be that Advagg might support it
    – Clive
    Jan 9, 2019 at 12:46
  • thanks @Clive, I tried that module unfortunately it does not work well when public:// is taken over by s3 file system. We have fixed the issue using cloudflare, I will add it as answer.
    – arpitr
    Jan 9, 2019 at 19:08

1 Answer 1

0

As Clive mentioned there is no config on s3 which could automatically compress the assets on s3.

The way we fixed it in our case was to add cloudflare CDN service(already in use) in front of s3 file system.

In order to route the s3 assets request via CF we added a proxy subdomain for our drupal origin. So if Drupal site was running on site-url.com we added a proxy subdomain as s3-<env>.site-url.com. We added a page rule in CF to override host to s3 bucket for any request to s3-<env>.site-url.com/*.

Now, the challenge was to override s3 hostname configuration in Drupal to spit out resources on s3-<env>.site-url.com/* instead of s3 bucket url. Big thanks to S3FS module maintainers for providing easy configuration to override that by adding following in settings.php

  $config['s3fs.settings']['use_cname'] = TRUE;
  $config['s3fs.settings']['domain'] = 's3-<env>.site-url.com'; 

Your Answer

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

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