How can I fix "(No max-age or expires)" with Amazon CloudFront?

So here’s the deal. I’m using Amazon’s CloudFront product to deliver the .gif files for my site’s template. There are about 30 individual files so it should help speed up the site. At some point I might get around to making a CSS sprite, but for now I’m not worried about that.

The problem now is when I look at my WPT results, it shows many lines of:
[b]FAILED (No max-age or expires) -[/b] (one for each gif file).

So I know how to set the expires on my regular web server. I use apache so I put this in my .htaccess in the root:

# 2,592,000 is 30 days caching <FilesMatch "\.(gif|png|jpg)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch>

So the main question here is how do I enable that sort of cache control on AWS? I’m using a subdomain as the CNAME for AWS, however the domain name of my main site is and the CDN domain name is actually a different domain, e.g.

(The reason I’m using a .net domain for the CDN files is that domain is cookieless which is supposed to be a good thing when it comes to speeding things up)

I assume you are using S3 for your content served through CloudFront, right? If so, you need to set the expiration on the S3 files themselves:

The domains themselves really don’t have anything to do with it - the header is set on a request-by-request basis by the thing serving the files (and I doubt your Apache is in the path for serving the files through CloudFront).

On a separate note, there is nothing special about “.net” that makes it cookieless. It is just whatever convention you use for your app and where you set your own cookies.

Hi, thanks, I’ll check the link out. Yes I’m using S3 to upload and serve the content to CloudFront (I’m not aware of any alternatives to that).

The only reason I’m using the .net is so that it’s a separate domain (one with no content, it’s just used for the CDN so it doesn’t trigger the cookieless domain thing in the report). My main website sets cookies at “”, and the .net domain I’m using I use for multiple sites so in a way it makes it easier to manage all my CDN files in one spot. You see, I use , , , etc. for my sites so it works out good that way.

I realize that the .net extension has nothing to do with it being cookieless. I just don’t use that domain for anything but the CDN.

Is your actual application an AWS/EC/S3 app? If not, there are much cheaper and easier CDN’s than Cloudfront. It works great if your app is built on their platform but it’s quite a hassle if you are using it JUST for the CDN.



No, I have an Apache / cPanel web host company I’m using, and then using CloudFront simply for static images, CSS, etc. files. For the most part I have static/PHP web sites with phpBB forums. I only use the CDN in hopes of speeding up my sites a bit.

As it is I only pay $3-5/month for usage so it is pretty cheap, although it was not easy to setup. I’ve been running websites for 10 years now but I’m not a hardcore coder, more of a web site manager although I solely run them all.

Honestly my biggest concern is speed, speed, speed when it comes to a CDN. Although though my pockets aren’t that deep… :wink:

I’ve been using MaxCDN for the last year and have been exceptionally happy. They only gap right now is Asia and they’ve been working on setting up a POP there but I’m not sure what the status is (just Europe and the US right now).

The configuration is mind-numbingly easy. They work as a reverse proxy and pull the files directly from your site automatically as needed and pass all of the headers through. If I add a new file to my site at I can also reference it through and it will be pulled automatically by them when it is requested the first time. It basically “just works”.

The pricing is really competitive (though not as low as it looks like you are paying for CloudFront). $29.95 for the first year (up to 1TB) if you use this code: and $99 per year after that. (I don’t get any kickbacks/affiliate or anything, just a very happy paying customer - one that doesn’t like spending money :slight_smile: ).

Pat, I’m revisiting this topic. I’ve signed up for MaxCDN using your coupon code. I’ll give 'er a try.

So far it’s way less complicated than S3/CloudFront. WAY more user-friendly. And for the first year it is cheaper since I will stay under 1TB transfer… thanks Pat.

Swanny, if you stay with Cloudfront, you can set meta data on objects in an S3 bucket. I set Cache-Control, and that gets picked up by Cloudfront, which it issues as an HTTP header.

Setting meta data via the AWS S3 API is challenging. There are desk-top programs to do this. One such program is Bucket Explorer (

As of now, I have no intention of staying with CloudFront. I’m happy with MaxCDN and am slowly moving everything over there. It’s just too easy to set the expires (.htaccess in main site). And using Pull zones it’s too easy to maintain the files, as it just grabs them off the /cdn folder I put on my own sites.

MaxCDN is SOOOO much easier to use it’s not even funny. I see they use all SSD hard drives which probably makes a difference too.

Google directed me to this post. I just wanted to say…

pmeenan: Wow, thanks! I’ve spent the entire WEEK struggling with Amazon’s Cloudfront. By pure luck I ran across the thread via Google; decided to give MaxCDN a try. At 7:49pm I got the “confirm your registration” email from MaxCDN. By 8:25pm I had it working. It’s like magic!

swanny is right, it’s so much easier it’s not even funny. (And as for Zhami - I know that’s what the docs say, and I assume it even works for some people. But I spent 8 hours playing with the S3 APIs, and Cloudfront just ate my Expires and Cache-Control headers.)


I had the same “No max-age or expires” results for my images that are stored on s3 and served by cloudfront. I’ve specified in s3 the meta tag cache-control. I’ve tried max-age=2592000 and public,max-age=2592000. It lasted all day long.

I just reran the test in order to put a link in this thread and… it’s ok now! I’m happy but has anyone encounter the same issue with cloudfront or know what it could mean ?

Best regards,