doutanggun9816 2015-04-09 15:19
浏览 75

Javascript / Jquery / PHP加载页面 - 如何?

I have a website that has a-lot of elements and loads quite slowly http://www.uberdice.com. I was looking for a way to have a loading page that specifies the page is loading, as this is more pleasing than just a white page.

A desired example would be http://primedice.com.

I have searched around but none of the suggested examples have seemed to work, or I am just putting them in the wrong place.

I created this div:

<div id="loading" style="width: 100%;
 height: 100%;
 background: black;
 background-attachment: fixed;
 background-position: top;
 background-size: 100% 100%;
 position: absolute;
 color: white;">Loading! Please calm down guy...</div> 

Which I was going to use as the loading page and this script to disable it.

<script type="text/javascript">
document.getElementById("loading").style.display = "none";
</script>

However when I implemented this, it still gave me a white screen and I saw the 'loading' div briefly blink up a few ms before the full site loaded. I don't think the server is slow as the ping is normal and https://uberdice.com/test.php loads quickly.

Can anyone provide any solutions?

This is the current index.php file:

<div id="loading" style="width: 100%;
height: 100%;
background: black;
background-attachment: fixed;
background-position: top;
background-size: 100% 100%;
position: absolute;
color: white;">Loading! Please calm down guy...</div>
<?php

header('X-Frame-Options: DENY'); 

$init=true;
include './inc/start.php';
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $settings['title'].' - '.$settings['description']; ?></title>
<meta name="Keywords" content=“Dogecoin, Dice, Bets, Betting”>
<meta name="Description" content=“Exclusive Dogecoin Dice Site - 50% of ALL profits go back into Dogecoin development. In association with forum CryptoBoard.org.”>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="themes/<?php echo $settings['activeTheme']; ?>/main.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="content/ext/msgbox/Scripts/jquery.msgBox.js"></script>
<link rel="stylesheet" type="text/css" href="content/ext/msgbox/Styles/msgBoxLight.css">
<script type="text/javascript" src="content/ext/qtip/jquery.qtip.min.js"></script>
<link rel="stylesheet" type="text/css" href="content/ext/qtip/jquery.qtip.min.css">
<script type="text/javascript" src="js/colors.js"></script>    
<?php include './js/includer.php'; ?>
</head>
<body>
<?php include './themes/'.$settings['activeTheme'].'/frontpage.php'; ?>
<!-- _COINTOLI_IDENTIFIER_2_ -->
</body>
</html>
<?php include './inc/end.php'; ?>
<script type="text/javascript">
document.getElementById("loading").style.display = "none";
</script>

Thanks.

  • 写回答

1条回答 默认 最新

  • dsutuyxe088689 2015-04-09 16:13
    关注

    The problem is the time it takes for the server to generate your page, the browser can't display anything until the server has sent the content to it. It's taking about 6s for the server to generate the content on the page, this suggest some slow queries.

    The loading bar you are trying to use only works where there is a lot of objects on the page that you need to load, such as a lot of large images. The actual HTML is sent to the browser quickly, but loading large images is done separately and takes time. But your issue isn't like this, the HTML of the page is taking a long time to be produced, and the server won't send any HTML to the browser until the full page is generated.

    There are a few things you can try. The first is identify the queries taking ages to load and optimise them (I'd try this first). The second is to load the frame of the page only, then load the content using Ajax.

    The third is instead of loading all the content for the page you can echo it out to the browser bit by bit as the HTML becomes ready. From how the page loads I'm assuming that you store all the content into a variable and once it's all ready echo it out to the page. This is as simple as echoing out the content, then keep echoing out bit after bit as it becomes ready instead of storing it in a variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?