交互到下一次绘制(INP)
了解 INP 这一衡量真实响应速度的核心网页指标,掌握它如何在一次访问期间计算,以及保持交互迅捷的技术。
交互到下一次绘制(INP) 是 CoddyKit 上的免费 Web Performance Optimization & Lighthouse 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web Performance Optimization & Lighthouse 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web Performance Optimization & Lighthouse 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Responsiveness as a Vital
Interaction to Next Paint (INP) measures how quickly the page visually responds to user input across the whole visit. It became a Core Web Vital, replacing First Input Delay.
INP vs FID
FID only measured the first interaction's input delay. INP is broader: it considers all interactions and the full latency through event handling and rendering, not just the initial delay.
What an Interaction Includes
Each interaction's latency spans three parts: input delay (waiting for the main thread), processing time (event handlers), and presentation delay (rendering the next frame).
How INP Is Reported
Across a visit, INP reports roughly the worst interaction latency (with an allowance for outliers on pages with many interactions), so it reflects the user's worst-case responsiveness.
The Thresholds
- Good: 200ms or less
- Needs improvement: 200-500ms
- Poor: over 500ms
The Main Thread Is the Bottleneck
Long tasks block the main thread so input cannot be handled promptly. Breaking up long JavaScript tasks is the single biggest lever for improving INP.
Yielding to the Main Thread
Break long work into chunks and yield so the browser can handle input between them. scheduler.yield() or a setTimeout based yield helps.
async function process(items) {
for (const item of items) {
handle(item);
await new Promise(r => setTimeout(r, 0));
}
}Defer Non-Urgent Work
Update the UI immediately for feedback, then run heavy work afterward. Patterns like requestAnimationFrame for visual updates and deferring analytics keep handlers short.
button.addEventListener('click', () => {
showSpinner();
setTimeout(doHeavyWork, 0);
});Reduce Rendering Cost
The presentation phase suffers from large DOM updates and expensive layout. Use content-visibility, virtualization, and minimal DOM changes to render the next frame faster.
Measuring INP
Capture INP in the field with the web-vitals library, and use the DevTools Performance panel's interaction track to see input delay, processing, and presentation for each event.
import { onINP } from 'web-vitals';
onINP(metric => console.log('INP', metric.value));Improvement Checklist
- Break up long tasks and yield.
- Defer non-urgent work after paint.
- Trim event handler work.
- Reduce DOM size and rendering cost.
Quick Check
How does INP differ fundamentally from the metric it replaced, FID?
Recap
You learned INP measures whole-visit responsiveness across input delay, processing, and presentation, with a good threshold of 200ms. Improve it by breaking up long tasks, yielding to the main thread, deferring non-urgent work, and reducing rendering cost.
用 AI 导师学习 Web Performance Optimization & Lighthouse — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「交互到下一次绘制(INP)」课时是免费的吗?
是的 — 「交互到下一次绘制(INP)」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web Performance Optimization & Lighthouse 课程的其余内容,请升级到 CoddyKit PRO。 Web Performance Optimization & Lighthouse 课程共包含 4 节课。
「交互到下一次绘制(INP)」这节课中我会学到什么?
了解 INP 这一衡量真实响应速度的核心网页指标,掌握它如何在一次访问期间计算,以及保持交互迅捷的技术。 你通过在浏览器中直接运行的动手代码来练习 Web Performance Optimization & Lighthouse,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Web Performance Optimization & Lighthouse 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Web Performance Optimization & Lighthouse 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「交互到下一次绘制(INP)」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Web Performance Optimization & Lighthouse 课中编写并运行代码吗?
能。每节 Web Performance Optimization & Lighthouse 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 核心 Web 指标入门
- 深入解析 LCP、FID、CLS
- 改善用户交互指标
- 交互到下一次绘制(INP)