Make WordPress Core

Opened 7 weeks ago

#62770 new enhancement

Move comment cookie handling to user/JavaScript space

Reported by: joostdevalk's profile joostdevalk 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:

  1. Set the appropriate cookies when user leaves a comment (JavaScript).
  2. Read those cookies and fill the form field values (JavaScript).
  3. Deprecate and unhook the wp_set_comment_cookies and the related sanitize_comment_cookies functions.
  4. Adjust wp-includes/blocks/comment-content.php to no longer set the values on the comment field and remove the call to wp_get_current_commenter().
  5. Adjust wp-includes/class-walker-comment.php to no longer set the values on the comment field and remove the call to wp_get_current_commenter() from the comment() function.
  6. Adjust the wp-includes/comment-template.php similarly.
  7. 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.

Change History (0)

Note: See TracTickets for help on using tickets.