• Hi,

    With the current version of WPRM, if someone is using the rating system, it has a great flaw which is causing issues with full page caching, especially if the page is cached at the CDN level.

    So, currently, if a recipe card is using the rating system and when the page is cached, and if I go ahead and add a rating it uses admin-ajax.php to update the rating — this is great.

    But when I reload the page, the cached page will still show the old ratings instead of showing the latest ratings. This is because inside

    <div class="wprm-recipe-rating-details wprm-block-text-normal">
    	<span class="wprm-recipe-rating-average">5</span> from <span class="wprm-recipe-rating-count">2</span> votes
    </div>

    The rating calculation is done at the PHP level. So, when the page is being served from cache and PHP is not getting executed, these values are not the latest values.

    It would be great if you could add another admin-ajax.php call for fetching the rating data. In this way, even if the page is cached, the admin-ajax.php will fetch the current data of the rating and will be shown inside the recipe card.

    So, the data inside the wprm-recipe-rating-average and wprm-recipe-rating-count classes needs to come from JS and not from PHP. This will make this plugin highly compatible with all page caching systems.

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Brecht

    (@brechtvds)

    Hi there,

    I don’t feel like this is a “great flaw”. It’s really just caching working as expected. Showing a cached version of the page instead of decreasing performance to get the latest version.

    For a visitor it doesn’t really matter if it says “5 stars from 13 votes” or “5 stars from 14 votes”. A regular visitors will not notice the difference at all.

    The rating that was given does count and the cache will clear automatically after x hours, so you haven’t lost anything.

    We do have a setting on the WP Recipe Maker > Settings > Star Ratings page that tries to force the cache to clear when a rating is given. But take note that this won’t work with all caching solutions.

    Thread Starter iSaumya

    (@isaumya)

    Yes, but there are some people who always wants to show the most updated count of the rating while also using cache. So, if you add an option to fetch the rating data dynamically using ajax it would greatly solve this problem. So, if you please consider that, it would be really helpful for many people that that. The page can remain in cache for a very long period of time while showing the updated rating count as it is handled by admin-ajax.php.

    Plugin Author Brecht

    (@brechtvds)

    Getting the value through AJAX requires a valid nonce, and that nonce expires after 24 hours, so the cache needs to get cleared daily anyway:
    https://docs.wp-rocket.me/article/975-nonces-and-cache-lifespan
    https://medium.com/myatus/wordpress-caching-and-nonce-lifespan-bb357d984da9

    Which means the rating will get updated daily as well. I feel like this is sufficient for what it’s used for.

    Thread Starter iSaumya

    (@isaumya)

    Yes, I agree with you but as it’s not a critical data, you can implement the ajax request without nonce or give an option to turn off nonce inside the settings page. Many plugins does this or give the option. So, if you implement the request without nonce then the page can be cached a very long period of time while showing the current data.

    Plugin Author Brecht

    (@brechtvds)

    I will add it to the idea list, but I have to admit that there are other priorities right now.

    Thread Starter iSaumya

    (@isaumya)

    If you want , I can write the code for it and then maybe send you a PR of you have a repo. Ofcourse if you allow that.

    Plugin Author Brecht

    (@brechtvds)

    You are free to do that, of course. We don’t use a public repository for development but could send the code to [email protected] and I’ll have a look.

    Thread Starter iSaumya

    (@isaumya)

    Hi @brechtvds,
    I’ve modified the plugin code to add this feature and send the codes to you via email. Thanks.

    Plugin Author Brecht

    (@brechtvds)

    ​Thanks, I appreciate it!

    ​I’m on vacation right now but will have a look when I get back.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Make WPRM rating System Page Cache Friendly!’ is closed to new replies.