Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a URL parameter (?p=234) to a file on Amazon Cloudfront doesn't force a refresh of the file [closed]

I have JS and CSS files being served through Amazon Cloudfront. Up until now I was using my own server running Varnish, and when I updated any JS or CSS file or I had to do to use that new version was to increase a counter on a URL param on the request for that file.

So the URL of the file being included would go from .../file.css?r=1 to .../file.css?r=2 and Varnish would think of that as a new file, request it and cache it and serve it from cache from that point on.

With Cloudfront I'm realizing it doesn't work like that, it still serves the old cached file (and I keep getting "hit from Cloudfront" on the HTTP response).

Any idea if I can change the behavior of Cloudfront for this?

Anything else I can do that doesn't imply actually changing the name of the file everytime I update the file? I also don't want to use cache invalidations through Cloudfront's API. I think that's too much work for what I'm trying to do here, and there's a limited amount of (free) requests per month I can make.

like image 611
manuelflara Avatar asked Apr 19 '12 22:04

manuelflara


2 Answers

Looks like you were about a month too early... in mid-May of 2012, Amazon announced that you could start using query strings to identify objects in your cloud front cache.

Here's a link to the announcement on their blog: http://aws.typepad.com/aws/2012/05/amazon-cloudfront-support-for-dynamic-content.html

Unfortunately, I don't see any links in my quick googling that describes how exactly you can do this but I'm sure it's buried in their documentation or control panel somewhere.

Hope this gets you going in the right direction.

like image 78
longda Avatar answered Oct 17 '22 08:10

longda


Unfortunately if you want to avoid renaming the files, invalidation through CloudFront's API seems to be the only available option at the moment. The pain of renaming the files can be minimized by automating deploy process, however.

like image 27
BluesRockAddict Avatar answered Oct 17 '22 07:10

BluesRockAddict