Query delay

Hello everyone!
I’m trying to create a members bar in my website header. I can get the data from the current user, but there is always a 1-2 second delay when I switch to another page. I would like to know if it is possible to remove this delay and have the member’s name and photo appear uninterrupted. thank so much!!

this is my code:


import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(function () {
  
  
 const user = wixUsers.currentUser;
 const userId = user.id;
 const loggedIn = user.loggedIn;
 
  if(loggedIn) {

   
      wixData.query("Members")
      .eq("_id", userId)
      .find()
      .then((results) => {
       
        $w("#BtnProfile").label = results.items[0].firstname;
        $w("#profileImage").src = results.items[0].image;
      })
  }
 
   
});

  1. You can use .get() instead. It’s a little bit faster (but you probably won’t notice).

  2. you can start running the query before the $w is ready. Maybe something like:

import wixUsers from 'wix-users';
import wixData from 'wix-data';
const user = wixUsers.currentUser;
const userId = user.id;
const loggedIn = user.loggedIn;
let is$wReady = false;
let member = null;
if(loggedIn) {
 wixData.get('Members', userId)
 .then(res => {
   member = res;
   bindData();
 })
}
$w.onReady(() => {
 is$wReady = true;
 bindData();
})

function bindData(){
 if(member && is$wReady){
   $w('#BtnProfile').label = member.firstname;
   $w('#profileImage').src = member.image;
 }
}