Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview does not work with max-age cache #46

Open
angry-dan opened this issue Mar 27, 2019 · 0 comments
Open

Preview does not work with max-age cache #46

angry-dan opened this issue Mar 27, 2019 · 0 comments

Comments

@angry-dan
Copy link

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:

  • browser requests example.com/preview
  • express server emits a 301 redirect to example.com/some-page
  • express server serves live version of example.come/some-page
  • prismic toolbar phones home, gets a preview ref tries to reload the page
  • expected result: browser reloads the page and user sees draft version.
    actual result: browser reloads the page from it's local cache not from the server, user still sees the live version.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant