我想在我的网站上实施paint timing步骤,但我无法在互联网上找到任何正常工作的代码
唯一的例子是文档中的每个地方。
var observer = new PerformanceObserver(function(list) {
var perfEntries = list.getEntries();
for (var i = 0; i < perfEntries.length; i++) {
// Process entries
// report back for analytics and monitoring
// ...
}
});
// register observer for paint timing notifications
observer.observe({entryTypes: ["paint"]});
我在我的网站上使用Laravel Blade
。如何在Blade
?
答案 0 :(得分:0)
你可以做类似的事情,或者不仅仅是console.log,这些值会对它们产生不同的影响。
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (entry.name == "first-contentful-paint") {
console.log("time to first-contentful-paint is " + entry.startTime + " ms.", entry)
}
else if (entry.name == "first-paint") {
console.log("time to first-paint is " + entry.startTime + " ms.", entry)
}
}
});
observer.observe({ entryTypes: ['paint'] });