Jump to content

HTML, JS | Pause page loading until an Async function in head completes

Go to solution Solved by Mira Yurizaki,
2 minutes ago, Aleksa Djordjic said:

Tnx for the info, and that is how i do it on the main page, load some stuff (scripts) and hide/show elements based on the login, but i would like to do it without any redirecting, i want to literally pause the page loading until that action completes

You can't pause page loading by way of pausing the HTML file being downloaded and rendered, because web browsers need the entire HTML document before it knows what to do with the web page. You'd have to send a minimal HTML document and use JavaScript to add the content after the fact.

The title is pretty explanatory of what i need, couldn't find it anywhere else so I'm asking if it is even possible

 

I dont know PHP, so i made my own Login API in C# and the client side is just JavaScript (idk if it is even possible with anything else)

 

I have a function in the head that checks for the login, if it fails it redirects back to the index and if it succeeds it keeps the page

image.png.07562ef9580d068028322a42c2e8266f.png

 

I dont mind people viewing the page without being logged in, the thing is, if they aren't logged in, sometimes the login process takes time and it lets other page contents load (images and that stuff) which causes a bit more bandwidth usage on the server side :/

 

Is there any way that i could make that function pause the page loading until it completes, and if it is successful resume the page loading...

Tried await, but VSC just returns it as an syntax error (actually, nvmd, might be VSC, it does it only on .php files, and it doesnt seem to affect the page loading)

 

Im sorry if i don't understand some stuff about JS and HTML, haven't done something like this before, im a Back-end Developer working mostly in C# .... not JS

 

Thank you !

Link to comment
Share on other sites

Link to post
Share on other sites

It'd be best to check if someone is logged in on the server end when someone requests a URL, then you can have the server send the appropriate page or redirect. Otherwise you can conditionally load in another script if you want (see https://stackoverflow.com/questions/15521343/conditionally-load-javascript-file)

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Mira Yurizaki said:

It'd be best to check if someone is logged in on the server end when someone requests a URL, then you can have the server send the appropriate page or redirect. Otherwise you can conditionally load in another script if you want (see https://stackoverflow.com/questions/15521343/conditionally-load-javascript-file)

Tnx for the info, and that is how i do it on the main page, load some stuff (scripts) and hide/show elements based on the login, but i would like to do it without any redirecting, i want to literally pause the page loading until that action completes

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Aleksa Djordjic said:

Tnx for the info, and that is how i do it on the main page, load some stuff (scripts) and hide/show elements based on the login, but i would like to do it without any redirecting, i want to literally pause the page loading until that action completes

You can't pause page loading by way of pausing the HTML file being downloaded and rendered, because web browsers need the entire HTML document before it knows what to do with the web page. You'd have to send a minimal HTML document and use JavaScript to add the content after the fact.

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, Mira Yurizaki said:

You can't pause page loading by way of pausing the HTML file being downloaded and rendered, because web browsers need the entire HTML document before it knows what to do with the web page. You'd have to send a minimal HTML document and use JavaScript to add the content after the fact.

I guess that answers my question, tnx

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×