"If you can't measure it, you can't improve it." The first step when doing performance work is to measure meaningful metrics to establish a baseline for improvement. In this lesson, we'll measure Time to First Contentful Paint, a user-centric performance metric. We'll first create a PerformanceObserver object and explore the information it captures. Next, we'll send that information to Google Analytics to track FCP over time. Lastly, we'll discover why PerformanceObserver is one of the few bits of Javascript that rightly belong in the head of your document.

const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
console.log(entry.name, entry.startTime);
// note: the ga call will only work on your actual domain, make
// sure the code is executed on your domain and not just in a test environment.
ga('send', 'timing', entry.name, 'userId', Math.round(entry.startTime));
}
});
observer.observe({entryTypes: ['paint']});

[HTML5] Track First Contentful Paint with PerformanceObserver and Google Analytics的更多相关文章

  1. WebVTT 及 HTML5 <track> 元素简介

    https://dev.opera.com/articles/zh-cn/an-introduction-to-webvtt-and-track/ 简介 网络视频文本轨道,简称为 WebVTT, 是一 ...

  2. What is Dark Social & Dark Traffic?

    What is Dark Social & Dark Traffic? By Iaroslav Kudritskiy Google Analytics is supposed to speak ...

  3. Top 22 Free Responsive HTML5 Admin & Dashboard Templates 2018

    Top 22 Free Responsive HTML5 Admin & Dashboard Templates 2018 May 18, 2018 Alex Ivanovs Website ...

  4. HTML5 Boilerplate - 让页面有个好的开始

    最近看到了HTML5 Boilerplate模版,系统的学习与了解了一下.在各种CSS库.JS框架层出不穷的今天,能看到这么好的HTML模版,感觉甚爽.写篇博客,推荐给大家使用.   一:HTML5 ...

  5. HTML5定稿

    HTML5定稿了,终于有一种编程语言开发的程序可以在Android和IOS两种设备上运行了 本文转载自: http://www.cnblogs.com/tuyile006/p/4103634.html ...

  6. HTML5移动Web开发(一)——HTML5和移动网站基本概念以及一些模拟器

    当前,手机设备发展迅猛.屏幕尺寸各不相同.存储和性能仍有局限性,如何结合HTML5的功能,在多平台上创建高性能.响应式的移动网站,是Web开发者所要面对的首要挑战.HTML5以及移动网站都是很有前景的 ...

  7. Web 开发精华文章集锦(jQuery、HTML5、CSS3)【系列二十七】

    <Web 前端开发精华文章推荐>2014年第6期(总第27期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML5 ...

  8. html5的发展历程和由此引起的政治斗争

    2007年,乔布斯断言拒绝Flash并预言HTML5时代来临,IT行业就对HTML5产生了一股宗教热情.HTML5有着许多出众的特性,可以直接在网页上绘图.嵌入音视频.实现信息互动,可以跨越iOS.A ...

  9. html5的发展历程

    20年磨一剑,HTML5作为下一代Web标准,她的语义之美.人性之美.简单之美.实用之美……如同一场革命,将Web从内容平台推向标准化的应用平台,并一统各在平台阵营的标准.2008年,HTML5发布首 ...

随机推荐

  1. vivo手机的坑-禁止微信浏览器网页点击图片,图片会自动放大

    这个坑让我郁闷极了,之前我的手机在微信浏览器打开网页点击图片时,啥事也没有 现在,咋回事,变了呢! 现在我打开微信浏览器网页面html,点击一个img标签的图片,图片会自动满屏放大,吓死宝宝了.其他人 ...

  2. Lucene.Net无障碍学习和使用:搜索篇

    一.初步认识搜索 先从上一篇示例代码中我们摘录一段代码看看搜索的简单实现: private TopDocs Search(string keyword,string field) { TopDocs ...

  3. ubuntu 18.04下,KMS_6.9.1服务器启动后,客户端连接一段时间因为libnice而crash的问题修复

    相应track issue: https://github.com/Kurento/bugtracker/issues/247 libnice crashes in socket code: g_so ...

  4. 使用0填充string(构造类似‘00001’的字符串)

    今天在对视频进行爬取的时候,发现url最后是000001,然后是000002,依次增加,而且每一个url请求只能得到一个分段了的视频,这种情况下构造url就成了一个问题. python有一个函数可以处 ...

  5. Bzoj3837 [Pa2013]Filary(随机化)

    题面 权限题 题解 这题有一个很好的性质,就是一定有$k>\frac n2$.接着考虑怎么做. 我们随机选取一个数$x$,然后将所有数与它作差,那么只需要找出$k$个差值使得他们的最大公因数大于 ...

  6. Python开发基础-Day17面向对象编程介绍、类和对象

    面向对象变成介绍 面向过程编程 核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西.主要应用在一旦完成很少修改的地方,如linux ...

  7. BZOJ 1934 [Shoi2007]Vote 善意的投票(最小割)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1934 [题目大意] 每个人对于投票都有自己原来的观点:1或者0, 他可以违背自己原来的 ...

  8. Problem D: 判断上否上三角矩阵

    #include<stdio.h> int main() { ][],i,j; while(scanf("%d",&n)!=EOF) { ; //flag用来做 ...

  9. [转]提示错误 package javax.servlet.jsp does not exist package javax.servletr.jsp.tagext does not exist

    你在JAVA servlet容器运行的时候没配置servlet-api.jar,tools.jar,rt.jar,jsp-api.jar的classpath 我的classpath= .;%JAVA_ ...

  10. [转]Spring配置之OpenSessionInViewFilter

    参考: OpenSessionInViewFilter作用及配置:http://www.yybean.com/opensessioninviewfilter-role-and-configuratio ...