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.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行