We all know how important it is to make a good first impression. It's important when meeting new people, and it's also important when building experiences on the web. On the web, a good first impression can make the difference between someone becoming a loyal user or them leaving and never coming back. The question is, what makes for a good impression, and how do you measure what kind of impression you're likely making on your users? On the web, first impressions can take a lot of different forms-we have first impressions of a site's design and visual appeal as well as first impressions of its speed and responsiveness. While it is hard to measure how much users like a site's design with web APIs, measuring its speed and responsiveness is not! The first impression users have of how fast your site loads can be measured with First Contentful Paint (FCP). But how fast your site can paint pixels to the screen is just part of the story.
Equally important is how responsive your site is when users try to interact with those pixels! The First Input Delay (FID) metric helps measure your user's first impression of your site's interactivity and responsiveness. FID measures the time from when a user first interacts with a page (that is, when they click a link, tap on a button, or use a custom, JavaScript-powered control) to the time when the browser is actually able to begin processing event handlers in response to that interaction. What is a good FID score? To provide a good user experience, sites should strive to have a First Input Delay of 100 milliseconds or less. To ensure you're hitting this target for most of your users, a good threshold to measure is the 75th percentile of page loads, segmented across mobile and desktop devices. As developers who write code that responds to events, we often assume our code is going to be run immediately-as soon as the event happens.
But as users, we've all frequently experienced the opposite-we've loaded a web page on our phone, tried to interact with it, and then been frustrated when nothing happened. In general, input delay (a.k.a. One common reason this might happen is the browser is busy parsing and executing a large JavaScript file loaded by your app. While it's doing that, it can't run any event listeners because the JavaScript it's loading might tell it to do something else. The above visualization shows a page that's making a couple of network requests for resources (most likely CSS and JS files), and-after those resources are finished downloading-they're processed on the main thread. This results in periods where the main thread is momentarily busy, which is indicated by the beige-colored task blocks. Long first input delays typically occur between First Contentful Paint (FCP) and Time to Interactive (TTI) because the page has rendered some of its content but isn't yet reliably interactive.
You may have noticed that there's a fair amount of time (including three long tasks) between FCP and TTI, if a user tries to interact with the page during that time (for example, by clicking on a link), there will be a delay between when the click is received and when the main thread is able to respond. Because the input occurs while the browser is in the middle of running a task, it has to wait until the task completes before it can respond to the input. The time it must wait is the FID value for this user on this page. What if an interaction doesn't have an event listener? FID measures the delta between when an input event is received and when the main thread is next idle. This means FID is measured even in cases where an event listener has not been registered. The reason is because many user interactions do not require an event listener but do require the main thread to be idle in order to run.
|