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
Thread Starter
Ed
(@coopeh)
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
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
Thread Starter
Ed
(@coopeh)
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
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
Thread Starter
Ed
(@coopeh)
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