After checking on Google PageSpeed Insights, I have optimised the images on several websites using jpegoptim and optipng.

Obviously a lot of the images are now smaller and they have new timestamps, but they have not been updated through the Amazon CloudFront CDN.

The expire headers in .htaccess have been set for one year.

There are many hundreds of images that have been optimised, so manually invalidating them is not that feasible.

What is the best way to do this?

1 Answer 1


If you have the names of the files you can paste those into CloudFront's invalidation web interface.

On Linux and Mac, you can get all the filenames easily by selecting the files in the file browser, copying them (Ctrl+C or Cmd+C) then pasting into a text editor. Then use find/replace to get them in the correct format for AWS. That doesn't work on Windows though.

Alternatively, you could write a super quick script in PHP to get the file names and output that for copy-pasting into AWS.

The other method would be to do it programmatically. Download the SDK and follow the tutorials and docs on the site for your chosen language.

  • I have decided to make a new distribution, as so many files need to be invalidated, it would be cheaper this way. Instead of going through the hassle of changing DNS CNAME records, is it possible to recreate the origin instead?
    – paradroid
    Commented Feb 21, 2014 at 3:39
  • I've asked here - webmasters.stackexchange.com/q/58530/2029
    – paradroid
    Commented Feb 21, 2014 at 3:43

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.