加快DedeCMS文章页显示速度的两个小技巧分享
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>第一步 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>处理文章页的Javascript,在默认模板中前面有一大段Javascript,可能有2KB多一点,每个页2KG,集少成多也不少了。我就把这段JS提取出来,另存为一个文件,以后只要下载一次就可以了。不过注意要把JS里的路径根据自己的情况替换一下。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>第二步 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>发现文章到点击次数那里卡住了,有时差不要十来秒,感觉很不好,原来在查数据,影响了速度。其实这里我们可以用AJAX方式写出来,具体做法是: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>1、修改模板把这行去掉,加上<span id="article_click"></span> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>2、在第一步所说的的JS文件里加入一个JS函数 </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function getClick(aid,mid) <br>
{ <br>
var taget_obj = document.getElementById('article_click'); <br>
myajax = new DedeAjax(taget_obj,false,false,'','',''); <br>
myajax.SendGet2("/plus/count.php?ajax=yes&mid=" +mid +"&aid=" +aid); //这里要根据情况改成网站的实际路径 <br>
DedeXHTTP = null; <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>3、修改plus/count.php文件,在exit()之前加入以下的代码 </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
if(!empty($ajax)) <br>
{ <br>
$row = $dsql->GetOne(" Select click From `{$maintable}` where {$idtype}='$aid' "); <br>
if(is_array($row)) <br>
{ <br>
echo $row['click']; <br>
} <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>3、把改为:& lt;script language="javascript" type="text/javascript">getClick({dede:field name='id'/},mid={dede:field name='mid'/});getDigg({dede:field.id/});</script>。其实getClick这个函数只要放在文章后面,哪里都无所谓。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我是刚开始用DEDECMS,感觉功能很好很强大,技巧方面暂时就这两点,经过这两步好,感觉显示速度快了不少。</span></p>
頁:
[1]