简体   繁体   中英

Prevent main page from flashing before login-page redirect

I feel like the solution will be simple. At least, I hope so.

I've got index.html, which is my main page, and the first thing it checks is whether or not the user is logged in or not.

var currentUser = Parse.User.current();
if (currentUser) {

} else {
    window.location = "login";
}

If the user isn't logged in, then he/she is redirected to the login page. The problem is that the main page flashes for a quick second before redirection. Of course, I understand that this is because checking whether or not the user is logged in takes just enough time to show the page for a split second.

What's the best way to solve this? The ways I've thought of would probably still flash a page. (Turning the login page into index.html would probably flash the login page for a second).

Output buffering ob_start()

Also, the session status should be checked server-side before generating output in order to reduce server load and improve smoothness of operation.

EDIT: I do assume a server-side script handles your user sessions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM