判断当前页面加载是否快速,通常是直接在浏览器中访问网站,看自己的直观感受是否快速。而客观的方法则是计算具体的页面加载时间并显示出来给看。
1、在当前主题的functM h t lions.php文件添加下面的代码:
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime$ w ( k g : ` q (() );
$times* i q = / etart = $mtime[1] + $mtQ ? Zime[0];
return true;
}
timer_start();
function timer_stop( $d0 o m z Wisplay = 0, $precision = 3 ) {
global $timesv ^ 8 ] z \tart, $timeend;
$mtime = explode( ' ', mi: J ] * f Ycrotime() );
$timeend = $mtime[1] + $mtime[0];
$timetota^ j W ^l = number_format( $timeendW x Z ! X e | 4 B - $timestart, $preV x Y l : )cision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $displ^ i 7 D 7 6ay ) {
echo $r;
}
return $r;
}
2、在要显示加载时间的位置添加调用代码:
<?php echoL t : timer_stop();?>B I 0 Q t X r
3、保存后,到前台刷新页面即可显示加6 G W E + 5 X W \载时间。
代码来自:https://app.typecho.me/coder/load-time.html
