What’s the best way to implement AJAX in WordPress?

The crude alternative most people resort to is the one where you add a file and include several levels up. This is arguably worse for performance if not just as bad.

But there is a variant that works better, if we create our own AJAX entrypoint URL, and specify:

define( 'SHORTINIT',true);

Then include the WordPress environment, we can skip over the majority of the loading process. This is the way to go if you want super zippy AJAX requests. The downside is that we have to load some things ourselves, and some steps of the loading process are never executed.

See this answer for more detail Ajax takes 10x as long as it should/could