Use caching and keep widgets dynamic with Ajaxize

Getting my record label site to be super fast took months of diligence and a lot of trial and error. I wrote a detailed post about it on vizualrecords.com. Still, even though my site was fast, occasionally the shopping cart widget wouldn’t update properly using WP Super Cache.

While the newest version of WPSC (1.4 as of this writing) has a new dynamic caching function, I still can’t get my head around it so I searched for another solution and found one with Ajaxize. What Ajaxize does is make any php function you choose an ajax call so it will always remain fresh even with caching.

I had recently used Ajaxize for another site I had developed: crushtraders.com, to keep custom post type queries current while using caching and it worked quite well. For vizualrecords.com, I needed to ajaxize my Cart66 shopping cart widget and my login widget so that they would always show their current states. Ajaxize to the rescue.

To use Ajaxize, you can enter in any php function as is on your site and the plugin wraps your function in an ajaxable div which you then insert into your theme, replacing the original function. Alternatively, you can create your own functions in your functions.php file which is what I went with.

On vizualrecords.com, I registered a single sidebar for the shopping cart: sidebar1. Before Ajaxize, the sidebar call was in my header.php file:

With Ajaxize, I simply wrapped that call in another function like so:

Notice the echo’d jQuery – this was needed in order for the javascript to work within the ajaxized function. Another caveat with Ajaxize is that any functions you want to ajaxify cannot have any parameters so that is why I couldn’t just Ajaxize the get_sidebar('sidebar1'); call directly.

Now, the Cart66 shopping cart widget remains in its most current state on every page and I can use the most robust caching settings without having to worry about the cart staying fresh.

According to Cart66, the widget shopping cart doesn’t work at all with caching but I think this will prove them wrong.

See All Posts →