What strategy should I take when I want to serve different data to different users with (Blitz) cache? Logged in users get one set of prices (that can vary depending on their price group memberships), users that are not logged in don't see prices at all.

I read and implemented a test of Dynamic Content as described in the Blitz Cache documentation, and the result looks promising. Lighthouse says between 97-99 on performance with a 0,6s Fist Contentful Paint, serving gzipped caches from Blitz Storage on the Hyperlane VPS (I will test Cloudflare too).

The question is rather about the potential user experience of having the prices ajaxed into the body of the html document. I've never seen any site do it this way before. Have a look at the result. Pay attention to how the prices appear and the related network events on the right:


Ajaxing in content

(I realize that the defaultPrice is passed as a parameter to the productPrice template, and therefore the price is exposed - I've later replaced it with an encrypted string using the free plugin Cryptographer)

1 Answer 1


It looks like your approach is working rather well, so I'll assume you are simply asking for an alternative approach.

To make 1 AJAX request rather than the 80 or so that the page is currently making, I would use Blitz's dynamic content feature to load all of the products in one single template. In that template you can check whether the user is logged in, and hence whether to the display the prices or not, as you are already doing.

An alternative alternative would be to use Sprig, see the dynamic content recipe. Sprig gives you more control over how things are dynamically loaded. You could even tweak the way products are loaded to create a smoother user experience. For example, cache the products without the prices (the default for non-logged in users) and on page load, use Sprig to re-render the component with or without the prices (based on the user type).

  • I was wondering whether my approach was a good solution. After I wrote the question, I started googling for dynamic content in cached pages and found some thoughts on the subject. I have already tested Sprig for other use cases, and I will have an extra look at the framework as you suggested. So maybe my question is rather: Have you got any experience with dynamic content in cached pages - and how would you do it?
    – nitech
    Feb 4, 2021 at 7:42
  • I would use Sprig if I had another use-case for it on the site, otherwise the approach in my answer.
    – Ben Croker
    Feb 4, 2021 at 8:12
  • I am hesitant to load the products via Ajax because of the speed benifit of caching. Also, it is recommended to serve any content you want Google to know about as a part of the cached content (although I know it is said that Google runs JS).
    – nitech
    Feb 6, 2021 at 20:08
  • I added to my answer to about how to achieve a smoother user experience using Sprig.
    – Ben Croker
    Feb 7, 2021 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.