1

this is a follow up question to this one What's the best way to version CSS and JS URLs - part 2

If I have my static files on Amazon cloudfront and have the file's URLs mentioned in my code. How will I be able to do versioning of my CSS files, so that the browser retrieves the latest version of the file when I update it on cloudfront.

Couple of things I do not want to do when I am doing this are

  • change the filename in cloudfront and change the urls everywhere in the code
  • and then restarting the application server

thanks

2
  • Please try to keep your question limited to one actual question. You can always edit your question if your need to clarify what you're looking for.
    – John Conde
    Jan 24, 2011 at 13:59
  • @John, I only see one question. May 19, 2011 at 7:12

1 Answer 1

1

The browser will retrieve the latest version if the browser cached version has expired. It will not do an HTTP GET request until that happens. This is intended behavior, because you want the speed of not having the delay of testing if there's a newer version. This, and a way around it, has been explained in the questions you refer to.

Amazon CloudFront will fetch your file and keep it until it expires. That expiration time is 24 hours or the expiration time set in the header when it fetched your file, whichever is shorter. It will not come and fetch another version, it won't even test if there is a newer version. That is also intended behavior, so that the edge server can quickly accomodate the browser without having to wait for your site (or S3) to respond. That's why it's so fast.

You can work around this by using Object Invalidation. This is a feature of Amazon CloudFront that allows you to explicitly delete the file from the CloudFront edge servers. It takes a couple of minutes to complete, and there's a cost involved if you do it too frequently, but in the case of a script or CSS file that infrequently changes I don't see this as a problem. There's an API for it, and some tools (notably Cyberduck) allow you to do it for files that are stored in S3.

Combine the two, and I think you have the solution to your problem.

Your Answer

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

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