Hello, i have some code that i'm running in my masterpage.js to check time and conditionnaly render some elements, plus another DB call to populate a navigation element in my footer.
It's running in my onReady function. I'm affraid that this code is running on every page change. How would i make the code run on first load only?
Thanks!
You can keep a value in the memory and run the code if the value is undefined.
Something like:
//masterPage.js import {memory} from "wix-storage"; $w.onReady(() => { if(!memory.getItem("alreadyRun")){ //run your code here memory.setItem("alreadyRun", "true"); } })
Hi,
JD's snippet helped for my conditionnal rendering issue. The DB call seems more tricky to implement in my scenario, its pretty static data so i just hard coded my array for now :)
Let the code just run, if it is the right page-ID ! ! !
If page-ID = "myHomepage" ---> run the code
else DO NOT RUN THE CODE !