{"id":54271,"date":"2020-04-20T16:55:35","date_gmt":"2020-04-20T11:25:35","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=54271"},"modified":"2026-10-06T19:44:53","modified_gmt":"2026-10-06T14:14:53","slug":"clear-cloudfront-cache-purge-refresh-files","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/","title":{"rendered":"How to Clear CloudFront Cache: Purge and Refresh Files (Invalidation Guide)"},"content":{"rendered":"<p>Updated a CSS file, logo or image in your S3 bucket, but your site still shows the old version? That&#8217;s Amazon CloudFront serving its cached copy. To clear CloudFront cache, you create an <strong>invalidation<\/strong>, which is AWS&#8217;s name for purging or flushing files from the CDN. Here&#8217;s how to clear CloudFront cache from the AWS console and the command line, what it costs, and how to avoid needing it.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-54319\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-distribution.png\" alt=\"Clear CloudFront cache for a distribution\" width=\"688\" height=\"237\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-distribution.png 688w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-distribution-300x103.png 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-distribution-150x52.png 150w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/p>\n<p><strong>Quick answer:<\/strong> In the AWS console, open <strong>CloudFront \u2192 Distributions<\/strong>, select your distribution, go to the <strong>Invalidations<\/strong> tab and click <strong>Create invalidation<\/strong>. Enter the file paths to refresh (for example <code>\/css\/style.css<\/code>), or <code>\/*<\/code> to clear the whole cache, and click <strong>Create invalidation<\/strong>.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6ae77fc391acb\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #1a202c;color:#1a202c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #1a202c;color:#1a202c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6ae77fc391acb\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#What_is_CloudFront_caching\" >What is CloudFront caching?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#How_to_clear_CloudFront_cache_in_the_AWS_console\" >How to clear CloudFront cache in the AWS console<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Clear_CloudFront_cache_with_the_AWS_CLI\" >Clear CloudFront cache with the AWS CLI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#How_much_does_a_CloudFront_invalidation_cost\" >How much does a CloudFront invalidation cost?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Avoid_cache_problems_use_versioned_file_names\" >Avoid cache problems: use versioned file names<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Still_seeing_the_old_file\" >Still seeing the old file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Frequently_asked_questions\" >Frequently asked questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#How_long_does_a_CloudFront_invalidation_take\" >How long does a CloudFront invalidation take?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Can_I_clear_the_entire_CloudFront_cache\" >Can I clear the entire CloudFront cache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/04\/clear-cloudfront-cache-purge-refresh-files\/#Does_invalidation_delete_files_from_S3\" >Does invalidation delete files from S3?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_CloudFront_caching\"><\/span>What is CloudFront caching?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/aws.amazon.com\/cloudfront\/\" target=\"_blank\" rel=\"noopener\">Amazon CloudFront<\/a> is the content delivery network (CDN) from Amazon Web Services. It stores copies of your files (images, CSS, JavaScript, videos and even whole pages) on edge servers around the world, so visitors download them from a nearby location instead of your origin server or S3 bucket. That makes sites much faster, but it also means CloudFront keeps serving the old copy until it expires or you clear it.<\/p>\n<p>We used CloudFront with an S3 bucket to speed up QOT&#8217;s images and theme files around the world, and the first time we replaced a CSS file and nothing changed, it took a while to discover that &#8220;clear cache&#8221; in CloudFront is called invalidation. Like any <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2020\/02\/best-free-jquery-cdn\/\">CDN<\/a>, it&#8217;s caching doing exactly what it should.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_clear_CloudFront_cache_in_the_AWS_console\"><\/span>How to clear CloudFront cache in the AWS console<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Sign in to the AWS Management Console and open <strong>CloudFront<\/strong>.<\/li>\n<li>Click <strong>Distributions<\/strong> and choose the distribution that serves your site.<\/li>\n<li>Open the <strong>Invalidations<\/strong> tab and click <strong>Create invalidation<\/strong>.<\/li>\n<li>Enter one path per line, such as <code>\/images\/logo.png<\/code>, <code>\/css\/*<\/code> or <code>\/*<\/code> for everything.<\/li>\n<li>Click <strong>Create invalidation<\/strong>. It usually completes within a minute or two, and the status changes from &#8220;In progress&#8221; to &#8220;Completed&#8221;.<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-54320\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-cache-invalidation.png\" alt=\"CloudFront cache invalidation tab\" width=\"769\" height=\"198\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-cache-invalidation.png 769w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-cache-invalidation-300x77.png 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/cloudfront-cache-invalidation-150x39.png 150w\" sizes=\"(max-width: 769px) 100vw, 769px\" \/> <img decoding=\"async\" class=\"border alignnone wp-image-54321 size-full\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/clear-cloudfront-cache.png\" alt=\"Clear CloudFront cache with an invalidation\" width=\"544\" height=\"321\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/clear-cloudfront-cache.png 544w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/clear-cloudfront-cache-300x177.png 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/clear-cloudfront-cache-150x89.png 150w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/p>\n<p>CloudFront keeps a history of past invalidations. To purge the same files again, select an old invalidation and choose <strong>Copy to new<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"border alignnone wp-image-54322 size-full\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/copy-cloudfront-invalidation.png\" alt=\"Copy a CloudFront invalidation\" width=\"352\" height=\"149\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/copy-cloudfront-invalidation.png 352w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/copy-cloudfront-invalidation-300x127.png 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/copy-cloudfront-invalidation-150x63.png 150w\" sizes=\"(max-width: 352px) 100vw, 352px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Clear_CloudFront_cache_with_the_AWS_CLI\"><\/span>Clear CloudFront cache with the AWS CLI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you deploy often, the <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/reference\/cloudfront\/create-invalidation.html\" target=\"_blank\" rel=\"noopener\">AWS CLI<\/a> is quicker. Replace the distribution ID with your own:<\/p>\n<pre><code>aws cloudfront create-invalidation --distribution-id E1234567890ABC --paths \"\/*\"<\/code><\/pre>\n<p>To refresh only certain files:<\/p>\n<pre><code>aws cloudfront create-invalidation --distribution-id E1234567890ABC --paths \"\/css\/style.css\" \"\/images\/*\"<\/code><\/pre>\n<p>You can add this command to your deployment script or CI\/CD pipeline so the cache clears automatically after every upload.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_much_does_a_CloudFront_invalidation_cost\"><\/span>How much does a CloudFront invalidation cost?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>According to <a href=\"https:\/\/aws.amazon.com\/cloudfront\/pricing\/\" target=\"_blank\" rel=\"noopener\">CloudFront pricing<\/a>, the first 1,000 invalidation paths each month are free, and each extra path costs a small fee. A wildcard path like <code>\/*<\/code> or <code>\/images\/*<\/code> counts as just one path, even if it clears thousands of files, so wildcards are the cheapest way to purge a lot at once.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Avoid_cache_problems_use_versioned_file_names\"><\/span>Avoid cache problems: use versioned file names<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>AWS recommends versioning file names instead of invalidating all the time. For example, change <code>style.css<\/code> to <code>style.v2.css<\/code>, or add a version query string like <code>style.css?ver=2<\/code> if your cache settings include query strings. Browsers and CloudFront see a new file and fetch it immediately, with no invalidation needed. WordPress does this automatically for many theme and plugin files using <code>?ver=<\/code>.<\/p>\n<p>You can also control how long CloudFront keeps files by setting the cache policy&#8217;s TTL (time to live), or by sending <code>Cache-Control<\/code> headers from your origin. Short TTLs for HTML and long TTLs for versioned images, CSS and JavaScript work well for most sites.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Still_seeing_the_old_file\"><\/span>Still seeing the old file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Clear your browser cache<\/strong> or open the page in a private window. Your browser may have its own cached copy.<\/li>\n<li><strong>Check the exact path.<\/strong> Paths are case-sensitive and must start with a slash.<\/li>\n<li><strong>Clear other caches.<\/strong> If you also use a WordPress caching plugin or another CDN, purge those too.<\/li>\n<li><strong>Wait for &#8220;Completed&#8221;.<\/strong> An invalidation in progress may not have reached every edge location yet.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_long_does_a_CloudFront_invalidation_take\"><\/span>How long does a CloudFront invalidation take?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Most invalidations finish within a minute or two, though large ones can take longer.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_clear_the_entire_CloudFront_cache\"><\/span>Can I clear the entire CloudFront cache?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes. Create an invalidation with the path <code>\/*<\/code>. It counts as a single path for billing.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_invalidation_delete_files_from_S3\"><\/span>Does invalidation delete files from S3?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. It only removes the cached copies from CloudFront&#8217;s edge servers. Your original files in S3 or on your server aren&#8217;t touched.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Updated a CSS file, logo or image in your S3 bucket, but your site still shows the old version? That&#8217;s&#8230;<\/p>\n","protected":false},"author":4,"featured_media":54319,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"default","_kad_post_title":"default","_kad_post_layout":"default","_kad_post_sidebar_id":"","_kad_post_content_style":"default","_kad_post_vertical_padding":"default","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6],"tags":[49],"class_list":["post-54271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","tag-tutorials"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/54271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=54271"}],"version-history":[{"count":1,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/54271\/revisions"}],"predecessor-version":[{"id":63302,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/54271\/revisions\/63302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/54319"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=54271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=54271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=54271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}