1

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.

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, 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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