Support » Plugin: Top 10 - Popular posts plugin for WordPress » Changes to have Top10 plugin working with W3 Total Cache

  • Resolved postoffice33



    I was working with the plugin and when I installaed (and enabled) W3 Total Cache, the counters are not updated anymore.

    This is because currently the plugin generates in the page/post html code a <script> tag that includes the file top-10-addcount.js.php (that server-side increments the counters in the mySql DB).

    Unfortunately when you enable browser caching tags, the browser will NOT do this request if the page has been already visited (and cache is not expired).

    The solution to this is to do an AJAX call AND to add a random parameter value in order to have always a different URL, so avoid that the browser cache (again!) the same.

    So I changed the file top-10.php at line 75:

    $output = '<script>jQuery.ajax("' .$tptn_url. '/top-10-addcount.js.php?top_ten_id=' .$id. '&top10_rnd=" + (new Date()).getTime() + "-" + Math.floor(Math.random()*100000));</script>';

    This will ensure that the AJAX call is always done and the server can update the counters.

    Note that the changes is applied only to global stats counter (not the daily one that I am not using).


Viewing 15 replies - 16 through 30 (of 35 total)
  • I just started using W3 Total Cache too and found the same thing others are experiencing here.

    I added


    to the “Never cache the following pages:” on the W3TC page cache page – but when I look at my page source, it still shows the url for it as the subdomain for the cdn.

    Why would it work for gearhungry correctly but not work on my site?

    When I test site speed using pingdom, it shows the top-10 plugin as one of the slowest pages… but I suspect that’s because it’s cached on the cdn and not working correctly,

    Any suggestions?


    Plugin Author Ajay


    Christopheran, can you try just top-10-addcount.js.php in your “Never cache” option?

    Ajay, I’m sorry, my mistake.

    I had added the path to the page-cache not to cache section when it needed to be set in the cdn ‘rejected files’ section – just go confused going back and forth trying out different thing!

    Now that I have it in the right place – it is working, ie: not using the cdn for the top-10-addcount.js.php file!

    Thanks 🙂


    Plugin Author Ajay


    Sounds good Christopheran 🙂

    Ok, now I took the next step and added Cloudflare into the mix, so I’m using W3TC with MaxCDN and Cloudflare.

    It’s working surprisingly well, faster than having MaxCDN by itself.

    The only thing that doesn’t seem to be working is the top-10 js that displays the count.

    The count is being maintained and updated, just doesn’t show on the page.

    It seems to be related to Cloudflare’s Rocketloader. It puts this on the page in place of the regular src:

    <script type=”text/rocketscript” data-rocketsrc=”″></script>

    The rest of the js files on the page are done the same way, this is the only one that doesn’t seem to be working.

    I can turn off the rocketloader site-wide and then the count is displayed. I haven’t found a way to just exclude this script from the rocketloader… still researching though,


    Ah, ok, found it.

    I had to edit top-10.php a bit.




    $output = '<script data-cfasync="false" type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';

    That excludes it from rocketloader,


    Plugin Author Ajay


    Chris, is the rocketloader really an issue? I have the Cloudflare plugin on my site and it gives me the rocketloader output as well, but this works perfectly.

    hmm, well, when I turned it OFF site wide using Cloudflare’s admin section, the count showed, when I turned it ON, the count stopped showing.

    When I added the above code to exclude rocketloader from applying to top-10-counter.js.php it shows the count (while rocketloader is on with everything else).

    Rocketloader is on top-10-addcount.js.php and that is working ok. It’s just the top-10-counter.js.php that I had to turn it off for.

    I am using MaxCDN as well, but both addcount and counter are excluded from that and loading directly from my server.

    So it looks like, in my case, it’s rocketloader, but not sure why or what’s different between our sites. There is still a lot of this cloudflare/maxcdn stuff I don’t understand. I’m trying to though!

    Plugin Author Ajay


    Chris, I think I get your point.

    Seems like the counter is missing from my site as well. I’m going to try your fix above on my site as well. Never thought about this earlier.

    Do you think it makes sense to disable rocket loader for all the scripts Top 10 adds to the page?

    The top-10-addcount.js.php I have set up so it’s not on maxcdn – but it is being loaded with rocketloader and is still working, the count is incrementing ok. So I don’t think it needs to be excluded from Rocketloader.

    But I’m no expert, just an experimenter 🙂 You would know better than I if there is some other reason to exclude it.

    Plugin Author Ajay


    Thanks. Makes sense. Seems like it’s working fine. I’ll run my tests and hopefully all goes well.

    I’ll also check with Cloudflare on what exactly is going on.

    I’ve been told their customer service is not very responsive – but I have never contacted them myself. Let me know what you experience – hopefully they are helpful.

    Plugin Author Ajay


    We don’t really need their input actually. It’s just a matter of turning of async loading.

    And, if my implementation works, we won’t need to load JS anymore.

    Plugin Author Ajay


    I have added the the fixes for W3 Total Cache and the Rocketloader issue in v1.9.5 of the plugin. Do give it a spin and let me know.

    Hi Ajay,

    are you planning to include in the new release (1.9.5) the ‘AJAX’ suggestion I put at the beginning of this thread?

Viewing 15 replies - 16 through 30 (of 35 total)
  • The topic ‘Changes to have Top10 plugin working with W3 Total Cache’ is closed to new replies.