Cache support with W3 Total Cache plugin

If you use page caching for your website with some cache plugin, ratings may not be always up to date because most visitors will get cached version of the page with outdated rating. But, there is a way to fix this and allow display of actual ratings using dynamic loading.

Plugin has a built in support for this and can be configured with most caching plugins. Since W3 Total Cache is most popular and most powerful caching plugin for WordPress, here are instructions to set this up.

  1. Cache Support in GDSR
    Cache Support in GDSR

    Using page cache. This most commonly used caching method. It will generate static HTML pages to serve to visitors. Because of that, ratings in the page will not be current, since the page cache can be set to expire on different intervals. So, to solve that, GDSR can use AJAX to load actual ratings. Simply, enable cache support option on the plugin settings panel, like the image on the right.

  2. W3TC DB Cache Support
    W3TC DB Cache Support

    Using database cache.┬áIf you use database cache, you need to add exception into W3TC plugin to skip caching of queries connected to GDSR. You need to add wp_gdsr into the list of ignored query stems. Image on the right shows how this looks, and also shows another stem you can use: gdsr_. I personally don’t recommend using database cache because it can cause problems on dynamic websites, and adding too many exceptions, defeats the purpose of having DB cache active.

  3. Using minification. GDSR loads 2 CSS files and 1 JS file on the front end. One CSS file can’t be added to minify list in W3TC, but other CSS and JS can. CSS file you can minify is: ‘wp-content/gd-star-rating/css/rating.css‘. And JS to minify is: ‘wp-content/plugins/gd-star-rating/js/gdsr.js‘. It is recommended to have this JS file loaded in the header, and it must be loaded after jQuery, like on the image bellow.

    W3TC Minfy JS
    W3TC Minfy JS
  4. Always clear cache. Whatever change to the cache settings you make, you need to empty all W3TC caches.

Official GD Star Rating website uses W3TC plugin with page cache and minification, and there you can see all this in action. That is all you need to know about using W3 Total Cache plugin caching. Similar methods can be used for other cache plugins.

Comments

Leave a Reply