Showing one random collection item on refresh (bypassing the 12 hour CDN server refresh)

I’m experiencing the same issue @JoeMillion. Did you figure out how to make sure it doesn’t rotate through the same items too often? Let me know! That would be very helpful. Thank you :slight_smile:

I gave up on it in the end, I wasn’t able to find a way to make it work as desired.

Here’s a nocode attribute that will allow you to sort your list randomly on every page refresh.
It will work with any collection list filter settings.

And a cloneable to demonstrate it;

I LOVE YOU, DUDE! If you come in Berlin, I will buy you a beer!

I have over 140 items in my cms list. The code works great, but my page keeps loading those hidden items until my browser gives up. Is there a way to not just hide (display:none) them from the layout, but stop the browser from rendering the other 139 items?

Webflow does not provide dynamic filtering so you either use it the way it is designed (CMS collection list random, limit one) or use the hack to pull the list and filter with JS which is not performant.

The ideal solution is to avoid using a collection list at all and remotely fetch a random item on page load via JS and a remote API.

1 Like

Hi Julia, I’m not sure which solution you’re using.

With 140 items you can use 2 collection lists. Sort and filter them identically, and then set the first to display 1 - 100, and the second, 101 - 200.

You’d need a small script to merge them and then randomly sort them.
If you will only ever show a single item and you want to get creative, you may even be able to skip the sort step, and create your random number as a piece of CSS that just shows the Nth item.

That’s likely the most performant way since all of your data is retrieved in the initial page load, however as @webdev indicated, it doesn’t scale well if your number of items will grow significantly as you’ll need itemcount/100 collection lists in the page.

If your items list will grow, you’d do better building a dynamic JS-fetch based solution out of the gates.

1 Like