Opened 7 weeks ago
#62770 new enhancement
Move comment cookie handling to user/JavaScript space
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | |
Focuses: | performance | Cc: |
Description
WordPress uses cookies to save people's comment details. As soon as someone has such a cookie, due to how this currently works, it becomes impossible to proxy cache their pageviews on every URL that has comments enabled, which in reality means almost every proxy cache solution excludes everyone with a comment cookie from its cache.
See, for example, Cloudflare's recommended settings for WordPress.
I blogged about this recently and learned from a bluesky reply that was sent in reply that one of the most popular caching plugins solves for this by setting the comment cookie timeout to 3 minutes, which, while technically a good solution, I think you'll agree, is less than ideal because it makes the functionality non-usable.
I think we should do what I recommend in the aforementioned blog post and move this entire functionality to JavaScript space. That means WordPress would ignore those comments on the server side, and both set and read them with JavaScript.
The code I used to do that is already in the blog post. The downside, of course, is that this would no longer work without JavaScript. But because that's such a low percentage of users and the "loss of functionality" is actually minor, I think that's a good tradeoff.
The required changes would be:
- Set the appropriate cookies when user leaves a comment (JavaScript).
- Read those cookies and fill the form field values (JavaScript).
- Deprecate and unhook the
wp_set_comment_cookies
and the relatedsanitize_comment_cookies
functions. - Adjust
wp-includes/blocks/comment-content.php
to no longer set the values on the comment field and remove the call towp_get_current_commenter()
. - Adjust
wp-includes/class-walker-comment.php
to no longer set the values on the comment field and remove the call towp_get_current_commenter()
from thecomment()
function. - Adjust the
wp-includes/comment-template.php
similarly. - Check other uses of
wp_get_current_commenter
- I think they're all used for showing a pending comment, but might be good to check.