WordPress.org

Ready to get started?Download WordPress

Forums

Ajaxize
[resolved] Strange Bug (7 posts)

  1. Ed
    Member
    Posted 1 year ago #

    Hi,

    You may not be able to help, but I have a strange bug when used with Varnish HTTP Cache. My site uses your Ajaxize plugin for 4 functions on the homepage, staff images, school images, testimonial text and recent news, http://primaryt.co.uk. I've told Varnish not to cache the functions, it shouldn't anyway as it's javascript, but every so often it caches and the result it sends back is "-1". All I can imagine is that the function fails at one point and returns the "-1" as it can't find the result, then Varnish will cache it as it doesn't understand the response it received.

    Ignoring all of the Varnish stuff above, my question is when would the plugin return a "-1" as the result? Also why would it do it on all of the 4 functions at the same time? If I can figure that out then I can make Varnish work around it. Ideally it would be best if it never got that response though :)

    I should add that I've never once seen this response when bypassing the cache.

    Cheers,
    Ed

    http://wordpress.org/extend/plugins/ajaxize/

  2. yoav.aner
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Ed,

    Ajaxize returns -1 in the (rare) case where the nonce does not match. The nonce is there to protect against unauthorized requests normally. When caching is involved, if it caches the nonce, it might create a situation in which the nonce is expired and this might produce this result.

    I believe nonces are usually valid for 24 hours. After that they expire.

    A workaround is to make sure the cache is refreshed at least every 24 hours. So for every page which include ajaxize, you should try to set the cache time to less than 24 hours.

    I might consider changing the plugin in future to (optionally) remove the nonce check, but not sure when I'll get round to it. Hope the workaround I suggested helps somehow though.

    Cheers
    Yoav

  3. Ed
    Member
    Posted 1 year ago #

    Hi Yoav,

    That makes perfect sense, it was doing it once every 24 hours. I've made some changes to try and catch it in Varnish, so that should help.

    Cheers,
    Ed

  4. yoav.aner
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Ed,

    Good to hear. I might change this behaviour in future, but for now that's the probably best workaround (and for most sites makes sense anyway... 24 hours is pretty long time for most use-cases to keep pages cached).

    If you're still having issues, please let me know and I'll do my best to help.

    Cheers
    Yoav

  5. Ed
    Member
    Posted 1 year ago #

    Just as an update, I never managed to get Varnish to catch it, as it was caching the nonce in the inline JS on the main page cache. I've removed all the nonce stuff from the plugin and it avoids caching fine now.

    Cheers,
    Ed

  6. yoav.aner
    Member
    Plugin Author

    Posted 1 year ago #

    Hey Ed,

    Yeah, I'm thinking of removing the nonce, since in 99.9% of the cases ajaxize is used to retrieve some data and does not make any changes (and since it does not allow passing a parameter, even when there's a change, like a visit counter, it's pretty safe). Since I can't tell for sure what people are using it, I'm not 100% comfortable to simply remove it. Maybe make it a configurable option in the settings... Hope to get round to it sooner or later.

    As far as Varnish however - you should be able to set the cache lifetime to less than 24 hours. Anecdotally, whilst I don't have much experience with Varnish, I did a little performance benchmark comparing it with other options. I found that whilst it was slightly better, it didn't justify the complexity involved compared to simpler caching solutions for me. You might be interested reading this benchmark on my blog: how much (cache) is too much?

    Cheers
    Yoav

  7. Ed
    Member
    Posted 1 year ago #

    Yeah a setting to change between it would be the best in my opinion, especially if people are using the example code to reload functions.

    We use Varnish as it suits our purpose, we don't just host WordPress, we have NodeJS, PHP and other services running through it. It gives us a nice heartbeat and lets us know if something has gone down across multiple servers. I agree that if you're just hosting WordPress then Varnish can be, in most instances, overkill. I have always been happy with W3 Total Cache on smaller instances, our installation of WordPress is a multisite setup hosting 10,000 blogs, so Varnish also helps us in this respect. It can be a dog to set up, but once you get the hang of it adding rules is child's play.

    Cheers again,
    Ed

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic