prismicio / prismic-toolbar

An embeddable UI for Prismic content and previews directly on your website.
12 stars 19 forks source link

Preview does not work with max-age cache #46

Open angry-dan opened 5 years ago

angry-dan commented 5 years ago

Hello, I've noticed that previews don't work when used in combination with caching.

Here's an example:

I've got a Node Express server which listens to two endpoints:

example.com/preview - which interprets prismic preview requests example.com/* - which reads a uid and returns a page.

The second of those two endpoints also emits a cache-control header allowing the browser (and our CDN) to cache the page for 2 hours.

When you activate the preview in prismic the following happens:

This happens because the method of refreshing here - https://github.com/prismicio/prismic-toolbar/blob/master/src/share.js#L29 - is to just set the window location to effectively be window.location. Really at this point it should call window.location.reload(true).

The CDN isn't an issue here, because it's already varying responses based on the cookie that gets set. It's the browser not making the request that's the problem.