Page onChange problem

Hi everyone,
I’m trying to combat slow page-loading times. I want to make it so that a “loading” box appears when a user clicks any button to go to a different page, so they get the impression they’re going somewhere. I thought I was on the right track but I get the following error when I try it:

Relevant code below:

import wixLocation from 'wix-location';

$w.onReady(() => {
wixLocation.onChange(pageChange())
 function pageChange(event) {
        $w('#boxLoading').show()
        setTimeout(() => {
            $w('#boxLoading').hide()
        }, 500)
    }
}

Perhaps this one ?

import wixLocation from 'wix-location';

$w.onReady(() => {
    wixLocation.onChange(()=>{pageChange()})
});

function pageChange(event) {
    $w('#boxLoading').show()
    setTimeout(() => {$w('#boxLoading').hide()}, 500)
}

Thanks for your response @russian-dima , I no longer get any errors but my box is not appearing… any ideas?

I also want to achieve same thing thanks @LMeyer @russian-dima.

@russian-dima the code is not working for me also. Do you know how can we achieve it?

After reading the wix-location onChange API it looks like it’s not possible to use it in this way… Can anyone verify?

One way is to use a Box pinned on center of screen. Before the navigation, show it, on new page loading $w.onReady hide it. The pinned element becomes global. On mobile it will be placed on header because the pin does not work on mobile (small screen).

Also searching for a solution, but till now no luck, sorry.
Keep trying…

LMeyer, what exatly is your situation?
You navigate by pressing buttons, where are this buttons located/placed and where do they navigate to? Navigating to dynamic-pages? External pages (urls)?

@russian-dima Thanks for looking into it, I appreciate your help. My site loading time is slow, and when users click to go to a new page it takes 5-8 seconds and looks like nothing is happening. I basically want a “loading” box to appear whenever someone starts to go to a new page.

I have a similar setup on a different page that works well, but the trigger is a button onClick event. I’m trying to figure out if there’s a way to have it happen universally using the page onChange event or something similar.

@lmeyer
Yes i understand. Will look for a solution.

@lmeyer
Another question. Why is the loading-time of your website slow? What causes this? Could it be done by another solution? What you are trying to do, is just a >> alibi-solution <<.

Perhaps you can speed up your site, by using another structure, or something like this.