Identify and fix Core Web Vitals issues
✓Works with OpenClaudeYou are a frontend performance engineer. The user wants to identify and fix Core Web Vitals issues (Largest Contentful Paint, First Input Delay/Interaction to Next Paint, and Cumulative Layout Shift) in their web application.
What to check first
- Run
npm install web-vitalsto ensure the Web Vitals library is installed - Check your current Core Web Vitals scores in Google PageSpeed Insights or use Chrome DevTools Lighthouse tab
- Review your largest images and third-party scripts in the Network tab (sort by size and time)
Steps
- Install the web-vitals library with
npm install web-vitalsto measure metrics programmatically - Import and call
getCLS(),getFID(), andgetLCP()functions at your app entry point to capture real metrics - Identify LCP culprits by checking which DOM element is largest at page load using Chrome DevTools Performance tab and "Largest Contentful Paint" marker
- Optimize LCP by preloading critical images with
<link rel="preload" as="image">, deferring non-critical CSS, and lazy-loading below-the-fold images - Check for layout shifts by inspecting elements with
will-changeor animations that move DOM elements without reserving space - Add explicit
widthandheightattributes to all images and video elements, or useaspect-ratioCSS to prevent cumulative layout shift - Minimize JavaScript parsing and execution time by splitting large bundles with dynamic imports or reducing Third-party Script size
- Test with
npm run buildand verify metrics improve in production mode, then re-check PageSpeed Insights
Code
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';
const vitalMetrics = {};
// Capture Core Web Vitals
getCLS((metric) => {
vitalMetrics.cls = metric.value;
console.log('CLS:', metric.value, metric.rating);
sendMetricToAnalytics('CLS', metric.value, metric.rating);
});
getFID((metric) => {
vitalMetrics.fid = metric.value;
console.log('FID:', metric.value, metric.rating);
sendMetricToAnalytics('FID', metric.value, metric.rating);
});
getLCP((metric) => {
vitalMetrics.lcp = metric.value;
console.log('LCP:', metric.value, metric.rating);
sendMetricToAnalytics('LCP', metric.value, metric.rating);
});
getFCP((metric) => {
vitalMetrics.fcp = metric.value;
sendMetricToAnalytics('FCP', metric.value, metric.rating);
});
getTTFB((metric) => {
vitalMetrics.ttfb = metric.value;
sendMetricToAnalytics('TTFB',
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Frontend Skills
Other Claude Code skills in the same category — free to download.
Component Generator
Generate React/Vue/Svelte components with props
Responsive Layout
Create responsive layouts with Tailwind/CSS Grid
Form Builder
Build forms with validation (React Hook Form, Formik)
State Management Setup
Set up state management (Zustand, Redux, Jotai)
Animation Creator
Create animations with Framer Motion or CSS
Dark Mode Setup
Implement dark/light mode toggle
Lazy Loading
Add lazy loading for images and components
SEO Optimizer
Add SEO meta tags, structured data, sitemap
Want a Frontend skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.