• Resolved jcostas81

    (@jcostas81)


    So I have been doing a lot of analysis of page speed times using tools such webpagetest and gtmetrix, and have noticed that one of the biggest slowdowns comes from POST admin-ajax.php which can be attributed to this action: update_views_ajax. I tracked this down to this plugin….any idea what the issue is here? It slows my site down by a couple of seconds. I just enabled the caching feature to 1 day so hoping that helps, but just wondering if anyone else had ever brought up this issue…thanks.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @jcostas81,

    That’s a known issue: WordPress’ Ajax API is slow.

    When any plugin or theme sends a request to admin-ajax.php, most of WordPress core is loaded: database options, themes, and plugins. This of course increments the load times of the response.

    Theme and plugin developers can create their own endpoints (and often people do) to make sure their requests are processed faster. The problem with this approach is that it’s basically a hack around WordPress’ official Ajax API that might break anytime WordPress changes something. This is the reason why they recommend using the official API instead of building your own. As you may already guess, WordPress Popular Posts uses the official Ajax API.

    Good news is that the next version of the plugin will stop using admin-ajax.php to send requests to the server. WPP will start sending requests via the WordPress REST API which, according to some studies, is around 15% faster than processing requests via admin-ajax.php (while 15% might not seem much, it really adds up in the long run).

    In the meantime, what can be done to improve things?

    • Use a caching plugin: serving static files will reduce the number of database requests needed to load your site.
    • Too many plugins can slow down your site: use those you really need, and make sure they’re high quality ones. Poorly written / non-optimized-for-performance plugins can impact your site’s speed.
    • If your site’s a high-traffic one, consider enabling Data Sampling.
    • Also, keep in mind that hosting a site on a shared server can also impact your site’s performance: other sites in the server might be using too much resources, affecting the rest of the sites in the process. If your site is struggling to handle traffic, it might be an indicator that you need to move to a better hosting.

    Hope that helps!

    humblehuman9

    (@humblehuman9)

    Great to hear that next version won’t be using using admin-ajax.php.. May I know when will be the next version released?

    Thanks in advance!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hey @humblehuman9,

    May I know when will be the next version released?

    Soonβ„’ πŸ˜‰

    Thread Starter jcostas81

    (@jcostas81)

    Thanks for the response Hector. I’d also love to know when the next version will be released :).

    As for your suggestions, I am currently using a caching plugin and a CDN. However, in terms of page caching, I am not caching HTML at the moment, just CSS and Javascript. Would caching HTML break anything in relation to the WPP, in terms of it being up to date? I have set my browser caching to a month, and the WPP caching to a couple of days, so I am wondering if that means the popular posts in theory would not reflect real-time (which is ok), and if it wouldn’t be updated for a month (not great)?

    I’ve also read some articles about turning off the Heartbeat API to get around the issue of WordPress Ajax API. I assume that would break this plugin, or keep it from working?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Thanks for the response Hector. I’d also love to know when the next version will be released πŸ™‚

    To be honest, and since @humblehuman9 is also curious about it, the next release of the plugin has been ready for quite some time now. I’m just waiting for WordPress 4.9.6 to be officially released (tomorrow, apparently). Need to write WPP’s 4.1.0 release announcement -a practice I recently adopted as it allows me to actually tell people about new features and bug fixes in more detail, changelogs are sometimes not enough- and once that’s done I’ll push WPP version 4.1.0 into the official repo.

    Would caching HTML break anything in relation to the WPP, in terms of it being up to date?

    The answer to that is: it depends.

    There are a few things you should be aware of when using caching plugins:

    • Many plugins and themes use WordPress Nonces to “help protect URLs and forms from certain types of misuse, malicious or otherwise.” These nonces have a lifetime of approximately one day, so if you cache your posts & pages for longer than that it might break things on your site. In WPP’s case, the plugin will stop tracking visits to your posts & pages if it gets passed an expired (thus invalid) nonce. The solution to this is to have your caching plugin regenerate its cache at least once per day (I configured WPFC to flush its cache every 10 hours, for example) to make sure new nonces are issued when the old ones expire.
    • Some caching plugins offer the ability to minify and bundle every JS file added to your theme. While this is a good thing as it helps decrease the loading times of your site (one JS file vs a zillion of them), some of these caching plugins don’t handle this properly and end up breaking things. If your caching plugin offers such a feature and you’re using it, hopefully it also offers a way to exclude WPP’s JS script from being minified / bundled (not that WPP’s needs any minification, it’s minified out-of-the-box anyways).

    Here’s a fresh example of the above: WPP stopped working.

    I’ve also read some articles about turning off the Heartbeat API to get around the issue of WordPress Ajax API. I assume that would break this plugin, or keep it from working?

    I honestly don’t know. I don’t think it would have any impact on WPP but can’t tell for sure as I haven’t messed around with the Heartbeat API yet.

    If you ever decide to experiment with it, I would be grateful if you could let me know whether disabling / modifying the behavior of the Heartbeat API has any effect on WPP or not.

    • This reply was modified 8 years ago by Hector Cabrera. Reason: Fixed typo
    Thread Starter jcostas81

    (@jcostas81)

    Hi – thanks for the quick follow ups, really appreciate it. To be honest, I am not an expert in caching or anything like that, so much of this is hard to follow! But I’m learning.

    I haven’t had any issues with my caching in relation to breaking things. I am using Hummingbird Pro as well as Cloudflare’s CDN. But only JS and CSS are being cached, not HTML. I also have Varnich Cache on my origin server….again, everything is working the way it should as far as I know.

    Will let you know if I discover anything with Heartbreak..

    Plugin Author Hector Cabrera

    (@hcabrera)

    Don’t worry, I’m no expert either. Just sharing what I know πŸ™‚

    If WordPress Popular Posts is reporting visits to your posts & pages chances are you don’t really need to change anything, which is a good thing!

    Plugin Author Hector Cabrera

    (@hcabrera)

    WPP 4.1.0 is out and so admin-ajax.php is a thing of the past!

    I’m marking this topic as resolved.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘WPP and admin-ajax’ is closed to new replies.