Current time: 10-17-2019, 03:12 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I fix "(No max-age or expires)" with Amazon CloudFront?
08-27-2010, 11:48 AM
Post: #1
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:
FAILED (No max-age or expires) - http://example.com/example.gif (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:
Code:
# 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 cdn.example.com as the CNAME for AWS, however the *domain* name of my main site is example1.com and the CDN *domain* name is actually a different domain, e.g. cdn.example2.net.

(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)
Find all posts by this user
Quote this message in a reply
08-27-2010, 10:12 PM
Post: #2
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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: http://htmlcssjavascript.com/web/setting...amazon-s3/

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.
Visit this user's website Find all posts by this user
Quote this message in a reply
08-28-2010, 11:55 AM (This post was last modified: 08-28-2010 12:18 PM by swanny.)
Post: #3
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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 ".example.com", 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 cdn.example.net/site1 , cdn.example.net/site2 , cdn.example.net/site3 , 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.
Find all posts by this user
Quote this message in a reply
08-28-2010, 02:24 PM
Post: #4
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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.

Thanks,

-Pat
Visit this user's website Find all posts by this user
Quote this message in a reply
08-29-2010, 02:42 AM
Post: #5
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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... ;-)
Find all posts by this user
Quote this message in a reply
08-29-2010, 09:14 AM
Post: #6
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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 http://www.webpagetest.org I can also reference it through cdn.webpagetest.org 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: http://www.webpagetest.org/forums/showth...hp?tid=324 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 :-) ).
Visit this user's website Find all posts by this user
Quote this message in a reply
01-25-2011, 02:45 PM
Post: #7
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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.
Find all posts by this user
Quote this message in a reply
01-27-2011, 11:54 PM
Post: #8
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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 (http://www.bucketexplorer.com/).
Find all posts by this user
Quote this message in a reply
01-28-2011, 01:40 AM
Post: #9
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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.
Find all posts by this user
Quote this message in a reply
02-02-2011, 05:30 PM
Post: #10
RE: How can I fix "(No max-age or expires)" with Amazon CloudFront?
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.)
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)