admin-ajax.php vs .load() in WordPress

Is it the only way to ajaxify your whole site or if there is any better way?

No, it’s not the only way. As you already know, you can indeed use .load(). As to what’s better? That’s wide open to debate and depends on personal preference, requirements, circumstances etc.

Cannot we use .load() method with less usage of code?

Less code, maybe. But does that always mean the “right” way? No.

Why admin-ajax.php method is preferred vs .load() method?

Hitting the AJAX handler instead of an asynchrous page load is less intensive on the server, and the HTTP response size is typically smaller (you’re only sending back the data you need, not a whole HTML document).

Now that’s not neccessarily a winning case for admin-ajax.php, but it’s how I’d argue that one could reason it is “the preferred way”.

Ultimately, it’s up to you. I agree that .load() would be easier, so I’d say go for it, and don’t get too hung up on the “right way” deemed by others without considering your own specific circumstances.

Leave a Comment