Opened 4 years ago
Closed 4 years ago
#51831 closed defect (bug) (duplicate)
WP REST API and Caching Issue
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.5.3 |
Component: | REST API | Keywords: | |
Focuses: | rest-api | Cc: |
Description
A follow-up to https://core.trac.wordpress.org/ticket/39861, cause I can not change the WordPress version to 5.5.3.
Hey @joehoyle and @lukecavanagh,
I just came across this ticket because I have a similar issue. We have implemented a dashboard in a WordPress submenu page. Imagine the following scenario:
- Open the dashboard
- JavaScript is fetching data via
GET
from a WP REST API endpoint - Click on another submenu, e.g. media library
- Use the back button from the browser
- Check the network log and you will see, that the WP REST API request got cached (
200 OK (from disk cache)
)
Tested on Chrome, but I think this happens on all browsers.
How can this be fixed? Using the following header disallows the browsers to cache the response:
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Add no-store
directive, see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control and https://www.mixmax.com/engineering/chrome-back-button-cache-no-store/
The solution? Add the no-store cache directive. It tells the browser to really not store anything at > all. So this works, and clicking the back button in Chrome will never serve up cached content: [...]
If you fix this, you need to be careful, because the directive should probably only be added on WP REST API calls.
Hi @mguenter,
Please add your comment to #39861 so we can keep the discussion focussed in one place. You don't need to change the version number to report the issue.
Thanks!