Frontend Performance: First Contentful Paint (FCP) Optimization
FCP refers to the first content drawing time. Optimization methods include: 1. Compress and delay non-critical resources; 2. Inline key CSS; 3. Enable server-side compression; 4. Preload critical resources reasonably; 5. Avoid blocking rendering JS operations; 6. Use asynchronous loading strategies; 7. Optimize image format and loading; 8. Using lazy loading and responsive images; 9. Use server-side rendering reasonably. These measures can effectively shorten the time for the first time of content presentation on the page and improve user experience.

Page loading speed is crucial to the user experience, and First Contentful Paint (FCP) is an important indicator to measure the time when a web page first presents content, directly affecting the user's first impression. Optimizing FCP is to make the page "look" and start working as soon as possible and reduce the sense of waiting.

What is FCP?
FCP is a core metric in Lighthouse performance score. It records the time when the page is loaded from the beginning to the browser for the first time it renders any visible content such as text, pictures, non-white canvas, etc. The shorter this time, the earlier the user will feel that the page is "moving" rather than blank.
Simply put: FCP reflects the time when the user first sees the content of the page.

Reduce the loading time of critical resources
One of the most direct factors affecting FCP is the loading and execution time of key resources. These resources include HTML, CSS, JS, and pictures required on the first screen.
- Compress and delay non-critical JS/CSS : Split out JavaScript or CSS that is not needed on the first screen, or delay loading.
- Use inline key CSS : Write the home screen style directly into HTML to avoid additional requests to block rendering.
- Enable server-side compression (such as Gzip or Brotli) : reduces transmission volume and speeds up loading.
- Use preload reasonably : Use
<link rel="preload">to load key resources, such as fonts or key JS in advance.
For example, if your main JS file is large and there is no code splitting, it will block the first rendering of the entire page. By loading on demand with tools such as Webpack, FCP can be significantly shortened.

Avoid blocking rendering operations
Many front-end operations will prevent the browser from drawing content quickly, thus slowing down FCP.
- Don't put a lot of synchronized JS in it: This will completely block HTML parsing.
- Avoid long-running JS tasks : Long tasks will cause the main thread to be occupied and rendering will be delayed.
- Use an asynchronous loading strategy : for example, add
asyncordeferattributes to the script.
For example, you introduce a synchronously executed third-party statistics script at the top of the page, which may have to process a bunch of logic before continuing to render the page, which will affect FCP.
Picture and resource optimization
Images are usually the heaviest part of the content on the home screen. If handled improperly, they can become a bottleneck in FCP.
- Using modern image formats : such as WebP, it can significantly reduce the volume compared to PNG/JPG.
- Set width and height attributes : prevent layout offsets and can also help browser render earlier.
- Lazy loading non-first-screen images : implement it with
loading="lazy"or Intersection Observer. - Use responsive image srcset : Provide the right size according to the device and reduce loading.
For example, a page has 10 large images, but only the first two are displayed on the first screen, and the rest can be delayed loading, so that the first screen content can be rendered first screen content and improve FCP.
Rational use of server-side rendering (SSR)
For applications that rely heavily on JavaScript, if all content is rendered by client, FCP is often worse.
- Using SSR can output the first-screen HTML content faster, allowing users to see things faster.
- Combined with Hydration technology, the interaction capability is activated based on server rendering.
For example, if a React application does not do SSR, the initial HTML may be empty, and the content will only start to be rendered after JS is loaded, which is very unfriendly to FCP.
Basically that's it. FCP optimization seems complex, but in fact the core idea is very clear: reduce the number and size of resources on the critical path and display the content as soon as possible . Although each step is not complicated, it can bring significant improvements when combined.
The above is the detailed content of Frontend Performance: First Contentful Paint (FCP) Optimization. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
How to use del and ins tags in HTML
Aug 12, 2025 am 11:38 AM
Thetagisusedtomarkdeletedtext,optionallywithdatetimeandciteattributestospecifywhenandwhythedeletionoccurred.2.Thetagindicatesinsertedcontent,alsosupportingdatetimeandciteforcontextabouttheaddition.3.Thesetagscanbecombinedtoshowdocumentrevisionsclearl
How to use CSS gradients for backgrounds
Aug 17, 2025 am 08:39 AM
CSSgradientsprovidesmoothcolortransitionswithoutimages.1.Lineargradientstransitioncolorsalongastraightlineusingdirectionsliketobottomorangleslike45deg,andsupportmultiplecolorstopsforcomplexeffects.2.Radialgradientsradiatefromacentralpointusingcircleo
How to use CSS selectors effectively
Aug 11, 2025 am 11:12 AM
When using CSS selectors, low-specific selectors should be used first to avoid excessive limitations; 1. Understand the specificity level and use them reasonably in the order of type, class, and ID; 2. Use multi-purpose class names to improve reusability and maintainability; 3. Use attributes and pseudo-class selectors to avoid performance problems; 4. Keep the selector short and clear scope; 5. Use BEM and other naming specifications to improve structural clarity; 6. Avoid the abuse of tag selectors and:nth-child, and give priority to the use of tool classes or modular CSS to ensure that the style is controllable for a long time.
How can you make an HTML element editable by the user?
Aug 11, 2025 pm 05:23 PM
Yes, you can make HTML elements editable by using the contenteditable attribute. The specific method is to add contenteditable="true" to the target element. For example, you can edit this text, and the user can directly click and modify the content. This attribute is suitable for block-level and in-line elements such as div, p, span, h1 to h6. The default value is "true" to be editable, "false" to be non-editable, and "inherit" to inherit the parent element settings. In order to improve accessibility, it is recommended to add tabindex="0&quo
How to create a responsive testimonial slider with CSS
Aug 12, 2025 am 09:42 AM
It is feasible to create a responsive automatic carousel slider with pure CSS, just combine HTML structure, Flexbox layout, and CSS animation. 2. First build a semantic HTML container containing multiple recommendation terms, each .item contains reference content and author information. 3. Use the parent container to set display:flex, width:300% (three slides) and apply overflow:hidden to achieve horizontal arrangement. 4. Use @keyframes to define a translateX transformation from 0% to -100%, and combine animation: scroll15slinearinfinite to achieve seamless automatic scrolling. 5. Add media
How to use the address tag in HTML
Aug 15, 2025 am 06:24 AM
Thetagisusedtodefinecontactinformationfortheauthororownerofadocumentorsection;1.Useitforemail,physicaladdress,phonenumber,orwebsiteURLwithinanarticleorbody;2.Placeitinsideforauthorcontactorinfordocument-widecontact;3.StyleitwithCSSasneeded,notingdefa
How to create a select dropdown in HTML
Aug 16, 2025 am 05:32 AM
Use and create drop-down menus; 2. Add tags and names with the and name attributes; 3. Set default options with selected attributes; 4. Group options; 5. Add required attributes to achieve required verification; a complete HTML drop-down menu should contain tags, names, options grouping and verification to ensure complete and user-friendly functions.
How to create subscript and superscript in HTML
Aug 20, 2025 am 11:37 AM
TocreatesubscriptandsuperscripttextinHTML,usetheandtags.1.Usetoformatsubscripttext,suchasinchemicalformulaslikeH₂O.2.Usetoformatsuperscripttext,suchasinexponentslike10²orordinalslike1ˢᵗ.3.Combinebothtagswhenneeded,asinscientificnotationlike²³⁵₉₂U.The


