Does code keep running when the page is closed?

I have created a custom sign-up. Upon signing-up, quite a few things are done. The contact details are pushed to the Wix database but also an external database. Furthermore, an email is sent to the user to confirm their email using sendGrid’s API.

All this happens in the backend upon the user clicking a submit button. If the user closes the page, does the code in the backend keep running until completion? Or does it just stop? Similarly, if they switch to another page on my site does that also stop the code from running? If they quit their browser, does that stop my code from running?


No, it does not. The backend will keep running, even if the user closes the browser, if you hit a frontend timeout, etc. The only thing that will happen in those cases is that the backend will no longer be able to return any result to the frontend, because the frontend was killed (close browser) or is no longer listening (front end tine out).

Ok, thanks for the response. I have one more question.

Let’s suppose this backend code takes 10 seconds to execute fully. The user clicks the sign-up button and the backend code starts executing. After 5 seconds, the user clicks the sign-up button again. What happens now? Does the old backend code stop midway through and get executed again from the start?


@alexpharaon02 No, the code will be executed a second time, but will prob return an error because the user already exists. That is why you should always prevent this on interface level by disabling the button upon first click.

@giri-zano Makes sense, thanks for the help and advice!