Answers.Body: <p>If it were me, I wouldn't use Cloudfront to offload the entire site. You can certainly use it for static assets but cache invalidation is really expensive. And as you've found it, troublesome. By offloading the static assets, you can keep the web server focused on just serving page requests.</p>
  
  <p>From your <a href="https://craftcms.stackexchange.com/questions/14494/using-crsf-ajax-form-posts-with-a-cdn">previous question</a>, it sounds you get a fair amount of traffic. </p>
  
  <p>Cache invalidation is a tricky subject. I don't know how often you update but a middle-of-the-road approach is using nginx or varnish.</p>
  
  <p>I like nginx myself because of its flexible <code>fastcgi_cache</code>. Even if you set the cache low, like 1 minute, you've just increased your capacity by an order of magnitude without much additional work on your part.</p>
  
  <p>nginx also allows you to cache by location so you could exclude caching any page with a form. POST requests by default bypass the cache.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T19:16:51.537Z
Answers.LastActivityDate: 2016-04-05T19:16:51.537Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: RitterKnight
Body: <p>We have a problem with using Live Preview on a site that uses CDN caching [CloudFront].</p>
  
  <p>When opening Live Preview a POST is sent to the actual page URL containing the information and the response is rendered</p>
  
  <p>/mypage</p>
  
  <p>However /mypage is in the CDN cache for GET requests and so when Craft sends the POST the headers and cookies are <strong><em>not</em></strong> forwarded to the origin. This causes a 400 error.</p>
  
  <p>We tried using a subdomain just for the CP, but of course the site is still on the cached domain and this is the domain used by the CP.</p>
  
  <p>Is there a way to use live preview with CDN caching?</p>
  
  <p><del>One potential approach would be to have a cookie set that is <em>only</em> set for logged in CP users, then we can set up a cache rule to bypass the CDN cache for all requests with that cookie.</del> </p>
  
  <hr>
  
  <p>Unfortunately our hosting partner informs us that we cannot have different caching profiles based upon a cookie. So we really need the Live Preview POST to be to paths that are not the actual cached live site paths.</p>
  
Tags: <control-panel><cache><live-preview>
Title: Live Preview and CDN caching
ThreadText: # Live Preview and CDN caching
  
  (Asked by: username_0 on 2016-04-05)
  
  We have a problem with using Live Preview on a site that uses CDN caching [CloudFront].
  
  When opening Live Preview a POST is sent to the actual page URL containing the information and the response is rendered
  
  /mypage
  
  However /mypage is in the CDN cache for GET requests and so when Craft sends the POST the headers and cookies are ***not*** forwarded to the origin. This causes a 400 error.
  
  We tried using a subdomain just for the CP, but of course the site is still on the cached domain and this is the domain used by the CP.
  
  Is there a way to use live preview with CDN caching?
  
  ~~One potential approach would be to have a cookie set that is *only* set for logged in CP users, then we can set up a cache rule to bypass the CDN cache for all requests with that cookie.~~
  
  ---
  
  Unfortunately our hosting partner informs us that we cannot have different caching profiles based upon a cookie. So we really need the Live Preview POST to be to paths that are not the actual cached live site paths.
  
  **Tags:** control-panel, cache, live-preview
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-05. Score: 1
  
  If it were me, I wouldn't use Cloudfront to offload the entire site. You can certainly use it for static assets but cache invalidation is really expensive. And as you've found it, troublesome. By offloading the static assets, you can keep the web server focused on just serving page requests.
  
  From your [previous question](https://craftcms.stackexchange.com/questions/14494/using-crsf-ajax-form-posts-with-a-cdn), it sounds you get a fair amount of traffic.
  
  Cache invalidation is a tricky subject. I don't know how often you update but a middle-of-the-road approach is using nginx or varnish.
  
  I like nginx myself because of its flexible `fastcgi_cache`. Even if you set the cache low, like 1 minute, you've just increased your capacity by an order of magnitude without much additional work on your part.
  
  nginx also allows you to cache by location so you could exclude caching any page with a form. POST requests by default bypass the cache.
  
  
  ---
  
  