When API REST caching is activated (with add_filter( 'rocket_cache_reject_wp_rest_api', '__return_false' );), API REST endpoints return cached data with HTML header instead of JSON header.
Hi @hippocampestudio 🤚
To be able to work on this issue, we need first to replicate it.
To help us, thanks to provide us the exact steps to reproduce the issue by using this template:
https://github.com/wp-media/wp-rocket/issues/new?template=bug_report.md
Describe the bug
When API REST caching is activated (with add_filter( 'rocket_cache_reject_wp_rest_api', '__return_false' );), API REST endpoints return cached data with HTML header instead of JSON header.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The cached JSON should be a valid JSON but is HTML
Screenshots
https://i.ibb.co/0VJmstK/Capture-d-cran-2020-04-17-15-41-08.png
Duplicate of #291
@Tabrisrp Thanks for the check. I'm going to close the #291 as this one as the steps to reproduce.
Reproduce the issue ✅
Identified the issue on localhost.
Identify the root cause ✅
The root cause is that the JSON is saved as .html and no JSON headers are provided.
Scope a solution ✅
@hellofromtonya , @Tabrisrp ideas?
Basically this will affect the .htaccess rules and also the serve_cache_file()
https://github.com/wp-media/wp-rocket/blob/57003cff362df710d36acb49085115ea4d09e0eb/inc/classes/Buffer/class-cache.php#L167
A solution can be to save the file as .json instead of .html
Another solution is to provide the JSON headers.
Both solutions should be applied IF the filepath contains: wp-json/wp/v2/
Effort ✅
I think this is an [M], but probably I am overestimating it 😄
@Tabrisrp What do you think?
Saving the file with the json extension seems the better choice to me.
I'm not sure we should bother too much with the htaccess rules, as the speed benefit is pretty low, and a JSON file is relatively small anyway.
What we need to take into account there is the following:
Hello,
Is there any news about this bug?
This issue is nearly 8 months old and still no solution :(
Any updates on this?
More and more websites are moving to use WordPress as a Headless CMS and caching these API endpoints is critical.
Most helpful comment
Hello,
Is there any news about this bug?