2

I have an EC2 server running apache (www.example.com) and mod_pagespeed is installed and working.

I have static content hosted on an Amazon S3 bucket (examplecdn.com)

When the html is served up from https://www.example.com, there are a couple of style references which are served from https://examplecdn.com.

Here's some sample html sent from https://www.example.com

<link rel="stylesheet" type="text/css" href="//examplecdn.com/assets/css/file_one.css"/>
<link rel="stylesheet" type="text/css" href="//examplecdn.com/assets/css/file_two.css"/>

I have read the documentation on mod_pagespeed, but I'm having trouble understanding it. I would expect the two requests to be rewritten into one http request.

I have confirmed using wget that https://examplecdn.com/assets/css/file_one.css is accessible from the www.example.com server

I have simplified my setup to use .htaccess for testing purposes. I can turn simple filters on and off easily without needing to restart the apache server. I'm trying to use the combine_css filter just to attempt to get a basic setup up and running. Here's my .htaccess file:

ModPagespeed on
ModPagespeedEnableFilters remove_comments
ModPagespeedEnableFilters collapse_whitespace
ModPagespeedEnableFilters combine_css

I know the documentation mentions lots of "Domain" settings, but I don't know which ones will do the trick. Can someone please tell me what changes I need to make to my .htaccess file in order to get this working?

Thanks!

noctufaber
  • 764
  • 2
  • 10
  • 24

1 Answers1

2

From combine css docs:

The filter will not merge together resources from multiple distinct domains, even if those domains are each authorized by Domain. It will merge together resources from multiple distinct domains that have been mapped together via MapRewriteDomain.

And from here:

This directive lets the server accept https requests for www.example.com without requiring a SSL certificate to fetch resources - in fact, this is the only way PageSpeed can service https requests as currently it cannot use https to fetch resources.

ModPagespeedMapOriginDomain http://examplecdn.com/ https://examplecdn.com/

Maybe this will work for you, but why not have those files local? They will be served by your apache server anyway.

[EDIT]

Tested it, this way worked for me:

pagespeed on;
pagespeed RewriteLevel CoreFilters;

pagespeed Domain *.example.com;
pagespeed Domain https://s3.amazonaws.com/mybucket;
pagespeed MapOriginDomain http://localhost https://s3.amazonaws.com;
pagespeed EnableFilters combine_css;

Tested with nginx but should work the same way with Apache. Also should make no difference if the mapped domain is on cloudfront.

at0mzk
  • 1,884
  • 14
  • 17
  • I am inclined to agree... doing this in front of S3 seems potentially counterproductive, at least in theory, but it might work out. The logical thing to do, initially, would be to get it working as desired with everything local on the apache server, and *then* make it work with content from S3. Then, as a bonus, you'd have a basis for a performance comparison. – Michael - sqlbot Feb 28 '17 at 10:39
  • I tried your suggestion, but it didn't work. :-( I forgot to mention that CloudFront is in the mix as well. I would like to better understand what configuration steps need to be made to utilize the FetchHttp behind the scenes process that pulls in these static resources and rewrites the html in order to serve it up optimally. Do you have any links to tutorials with better documentation and examples? – noctufaber Feb 28 '17 at 17:21
  • One other thing--I tried to reference a css file from the origin domain and it worked, so examplecdn.com and example.com are interchangeable. Unfortunately, the html cannot be easily changed to reference the css from example.com. I would like to find a way to use it as it is. Down the road I'm sure we'll likely change it. – noctufaber Feb 28 '17 at 17:29
  • @noctufaber tried it and worked for me, please see my edit. – at0mzk Mar 03 '17 at 01:45
  • Still unable to get it working. I'm giving up. I'm going to try a reverse proxy like Varnish and see how that goes. Thanks for your efforts. – noctufaber Mar 07 '17 at 17:15