Typecho获取当前页面加载完成速度时间
作者:xlnxin发布时间:2021-04-15分类:Typecho教程浏览:463
导读:判断当前页面加载是否快速,通常是直接在浏览器中访问网站,看自己的直观感受是否快速。而客观的方法则是计算具体的页面加载时间并显示出来给看。1、在当前主题的function...
判断当前页面加载是否快速,通常是直接在浏览器中访问网站,看自己的直观感受是否快速。而客观的方法则是计算具体的页面加载时间并显示出来给看。
1、在当前主题的functions.php文件添加下面的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function timer_start() { global $timestart; $mtime = explode( ' ', microtime() ); $timestart = $mtime[1] + $mtime[0]; return true; } timer_start(); function timer_stop( $display = 0, $precision = 3 ) { global $timestart, $timeend; $mtime = explode( ' ', microtime() ); $timeend = $mtime[1] + $mtime[0]; $timetotal = number_format( $timeend - $timestart, $precision ); $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s"; if ( $display ) { echo $r; } return $r; } |
2、在要显示加载时间的位置添加调用代码:
1 | <?php echo timer_stop();?> |
3、保存后,到前台刷新页面即可显示加载时间。
代码来自:https://app.typecho.me/coder/load-time.html
相关推荐
- 小程序和H5中canvas卡顿的性能优化方向和实践
- 微信小程序反编译报SyntaxError: Unexpected token ‘}‘ 不完美的解决方法
- 解决小程序反编译出现 app-service.js
- PHP把textarea中的回车换行替换为br
- zblogphp使用GetArticleList、GetList函数调用热门文章列表
- 淘宝给大家发6.5元新年购物红包啦,不要嫌少还有很多优惠,快来领取吧!
- 抓包软件Fiddler命令行和HTTP断点调试
- 正则匹配任意字符(常用正则表达式的书写)
- PHP开启openssl的方法-解决ZBlog主题插件无法启用的问题
- WordPress自动截取限定数字的摘要
- Typecho教程排行
- 最近发表