[wp-trac] [WordPress Trac] #62770: Move comment cookie handling to user/JavaScript space
WordPress Trac
noreply at wordpress.org
Thu Jan 2 20:31:34 UTC 2025
#62770: Move comment cookie handling to user/JavaScript space
-------------------------+-----------------------------
Reporter: joostdevalk | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version:
Severity: normal | Keywords:
Focuses: performance |
-------------------------+-----------------------------
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, [https://developers.cloudflare.com/support/third-party-
software/content-management-system-cms/speed-up-wordpress-and-improve-
performance/ Cloudflare's recommended settings for WordPress].
I [https://joost.blog/wordpress-comment-cookies-and-caching/ blogged about
this recently] and learned from a
[https://bsky.app/profile/remyperona.bsky.social/post/3leozya4o6c2k
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 [https://joost.blog/wordpress-comment-cookies-
and-caching/#h-the-solution-moving-comment-cookies-to-javascript-space
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62770>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list