简体   繁体   English

在登录页面重定向之前防止主页闪烁

[英]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. 我有index.html,这是我的主页,它检查的第一件事是用户是否已登录。

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). (将登录页面转换为index.html可能会使登录页面闪烁一秒钟)。

Output buffering ob_start() 输出缓冲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. 编辑:我确实假定服务器端脚本处理您的用户会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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