About Automated auditing, performance metrics, and best practices for the web.
Lighthouse 可以自动检查Web页面的性能。
你可以以多种方式使用它。
作为浏览器插件,访问chrome网上商店 搜索Lighthouse
插件安装。以两种方式使用。
安装成功后,访问想要检查的页面,开发插件,点击Generate report
,稍等片刻,你将会得到一份页面的检查报告。
访问想要检查的页面,打开开发者工具,切换到Lighthouse
标签使用。
以Node CLI方式使用Lighthouse可以得到最大灵活性,Lighthouse提供了许多参数使用。
Linghthouse 需要Node 14 LTS(14.x) 或更高版本。
> npm install -g lighthouse
> lighthouse --help
> lighthouse https://www.baidu.com --output html --output-path ./report.html
√ We're constantly trying to improve Lighthouse and its reliability.
...
--output
指定报告的类型;--output-path
指定报告的路径。
创建lighthouse_demo.js
文件,脚本如下:
const fs = require('fs');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
(async () => {
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};
const runnerResult = await lighthouse('https://www.baidu.com/', options);
// `.report` is the HTML report as a string
const reportHtml = runnerResult.report;
fs.writeFileSync('lhreport.html', reportHtml);
// `.lhr` is the Lighthouse Result as a JS object
console.log('Report is done for', runnerResult.lhr.finalUrl);
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
await chrome.kill();
})();
有没有自动化既视感,还可以设置 headless
模式。
> node lighthouse_demo.js
最终,会在当前目录下生成 lhreport.html
结果文件。
有一些Web网站基于lighthouse 提供服务,你可以登录这些网站输入URL检测网络性能。
Web Page Test
WebPageTest - Website Performance and Optimization Test
Calibre
Page Speed Tools for Teams - Calibre
Debug bear
Monitor Page Speed and Core Web Vitals | DebugBear
Lighthouse Keeper
病院で必ず目にする医療機器!そんな医療機器の基礎知識を初心者にも分かりやすく解説|医療機器の使用に備えて
...
以 web page test 为例:
生命不息,奋斗不止。每一份努力都不会被辜负,只要坚持不懈,终究会有回报。珍惜时间,追求梦想。不忘初心,砥砺前行。你的未来,由你掌握!
生命短暂,时间宝贵,我们无法预知未来会发生什么,但我们可以掌握当下。珍惜每一天,努力奋斗,让自己变得更加强大和优秀。坚定信念,执着追求,成功终将属于你!
只有不断地挑战自己,才能不断地超越自己。坚持追求梦想,勇敢前行,你就会发现奋斗的过程是如此美好而值得。相信自己,你一定可以做到!
最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!