Frontend Performance: First Contentful Paint (FCP) Optimization
Jul 19, 2025 am 02:58 AMFCP 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
async
ordefer
attributes 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)

React itself does not directly manage focus or accessibility, but provides tools to effectively deal with these issues. 1. Use Refs to programmatically manage focus, such as setting element focus through useRef; 2. Use ARIA attributes to improve accessibility, such as defining the structure and state of tab components; 3. Pay attention to keyboard navigation to ensure that the focus logic in components such as modal boxes is clear; 4. Try to use native HTML elements to reduce the workload and error risk of custom implementation; 5. React assists accessibility by controlling the DOM and adding ARIA attributes, but the correct use still depends on developers.

Shallowrenderingtestsacomponentinisolation,withoutchildren,whilefullrenderingincludesallchildcomponents.Shallowrenderingisgoodfortestingacomponent’sownlogicandmarkup,offeringfasterexecutionandisolationfromchildbehavior,butlacksfulllifecycleandDOMinte

StrictMode does not render any visual content in React, but it is very useful during development. Its main function is to help developers identify potential problems, especially those that may cause bugs or unexpected behavior in complex applications. Specifically, it flags unsafe lifecycle methods, recognizes side effects in render functions, and warns about the use of old string refAPI. In addition, it can expose these side effects by intentionally repeating calls to certain functions, thereby prompting developers to move related operations to appropriate locations, such as the useEffect hook. At the same time, it encourages the use of newer ref methods such as useRef or callback ref instead of string ref. To use Stri effectively

Create TypeScript-enabled projects using VueCLI or Vite, which can be quickly initialized through interactive selection features or using templates. Use tags in components to implement type inference with defineComponent, and it is recommended to explicitly declare props and emits types, and use interface or type to define complex structures. It is recommended to explicitly label types when using ref and reactive in setup functions to improve code maintainability and collaboration efficiency.

Server-siderendering(SSR)inNext.jsgeneratesHTMLontheserverforeachrequest,improvingperformanceandSEO.1.SSRisidealfordynamiccontentthatchangesfrequently,suchasuserdashboards.2.ItusesgetServerSidePropstofetchdataperrequestandpassittothecomponent.3.UseSS

WebAssembly(WASM)isagame-changerforfront-enddevelopersseekinghigh-performancewebapplications.1.WASMisabinaryinstructionformatthatrunsatnear-nativespeed,enablinglanguageslikeRust,C ,andGotoexecuteinthebrowser.2.ItcomplementsJavaScriptratherthanreplac

Vite or VueCLI depends on project requirements and development priorities. 1. Startup speed: Vite uses the browser's native ES module loading mechanism, which is extremely fast and cold-start, usually completed within 300ms, while VueCLI uses Webpack to rely on packaging and is slow to start; 2. Configuration complexity: Vite starts with zero configuration, has a rich plug-in ecosystem, which is suitable for modern front-end technology stacks, VueCLI provides comprehensive configuration options, suitable for enterprise-level customization but has high learning costs; 3. Applicable project types: Vite is suitable for small projects, rapid prototype development and projects using Vue3, VueCLI is more suitable for medium and large enterprise projects or projects that need to be compatible with Vue2; 4. Plug-in ecosystem: VueCLI is perfect but has slow updates,

Immutable updates are crucial in React because it ensures that state changes can be detected correctly, triggering component re-rendering and avoiding side effects. Directly modifying state, such as push or assignment, will cause React to be unable to detect changes. The correct way to do this is to create new objects instead of old objects, such as updating an array or object using the expand operator. For nested structures, you need to copy layer by layer and modify only the target part, such as using multiple expansion operators to deal with deep attributes. Common operations include updating array elements with maps, deleting elements with filters, adding elements with slices or expansion. Tool libraries such as Immer can simplify the process, allowing "seemingly" to modify the original state but generate new copies, but increase project complexity. Key tips include each
