Javascript localStorage not the same for desktop as phone

Topic summary

• Core issue: Random “sold in last 24h” and “people viewing now” counters act differently across devices. localStorage shows different values on desktop vs. phone for the same user; desktop only updates after a page refresh, while mobile updates on a 3000 ms interval.

• Goal: Display the same numbers for all users and across a user’s devices at the same time, constrained by min/max ranges (e.g., minSold 3–9, minViews 4–16), and update these globally at set intervals.

• Context/terms: localStorage is client-side and per-browser/device, so values are not shared between users or devices. A shared “map” was asked about to keep clients in sync.

• Input provided: Debug URL shared. Code snippets referenced but not effectively included; details appear incomplete, limiting diagnosis.

• Advice given: One reply claimed no need for localStorage and to “just use JavaScript,” noting this isn’t tied to admin data. No concrete implementation provided.

• Status: Unresolved. Open questions: how to implement synchronized, global counters (likely needs a server/shared store); why desktop interval updates fail while mobile works (requires actual code to debug).

Summarized with AI on December 15. AI used: gpt-5.

Hello, I got this script for displaying random numbers. Debug URL: Controllable LED Curtain – TrendBlend


I added it to my main-product.liquid but I am facing a problem. The localStorage appear different from mobile than desktop. And I’m also having another problem, the numbers update on phone. But the numbers only update on desktop after refreshing, so not when the number is actually updated (after 3000ms)

Hello @TrendBlend ,

Javascript is client side language, its run when page load.

Okay, thanks for your reaction, so it is not really possible to store the data in like a map and update the map every x seconds/minutes to always show the same number to different users/devices? And if it is not, do you maybe know why the numbers are not changing on desktop, but are changing on phone for this code?
Kind regards,
Stef

You are not a good explainer please explain me in detail actually what you want to do? secondly if you have any referance link kindly share.

Hello @iffikhan30 ,

I want to show a random number for units sold in the last 24 hours and how many people are looking at the product right now. This number has to stay between the minimum and maximum which is settled with this code:

minSold: 3, maxSold: 9, minViews: 4, maxViews: 16, for example. So for this code something like this would show:

5 sold in the last 24 hours.

12 people are looking at this product right now.

currently I am using localstorage which shows other numbers to different people at the same time. But also has the issue that when the same person looks on mobile the code outputs different numbers than when he looks on desktop. This would mean that he sees 3 units sold on mobile and 8 units sold on desktop AT THE SAME TIME. This is a problem, because the number should always show the same at a time. So for desktop and mobile the number should both show 3 units sold in the last 24 hours, but this number should be able to change (which is what the interval does). This does not only need to work for different devices but also for different users. So when one user is seeing 3 units sold, it should not be possible that another user sees 5 units sold at the same time. So the random numbers have to update at the same time for everyone, and not xx seconds (or minutes) after the code is being executed per person. Viewcount uses the same principes as soldcount. I hope this explains well, and you can help me with this.

Kind regards,

Stef

Hello @TrendBlend ,

understand your concerns, First think you don;t need to add localstorage because this sold items, max and min, Just add the javascript code simple so all screens show same even mobile and desktop, I pretty sure this count not come to the admin panel. use code,