跳到正文
cccskills
免费在 GitHub 公开

performance-optimization

Use this skill to identify and address common web performance issues. It covers bundle analysis and code splitting, lazy loading and image handling, caching headers, virtual lists for large datasets, and monitoring Core Web Vitals such as LCP, INP, and CLS.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Web performance optimization including bundle analysis, lazy loading, caching strategies, and Core Web Vitals

实测评分 未实测

查看安装方法

适用场景

  • Finding large JavaScript bundles and splitting code
  • Loading images and routes only when needed
  • Choosing cache headers for assets and API responses
  • Monitoring LCP, INP, and CLS in production

包含的文件(1)

  • SKILL.md4.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Performance Optimization

Bundle Analysis and Code Splitting

// Dynamic import for route-level code splitting
const Dashboard = lazy(() => import("./pages/Dashboard"));
const Settings = lazy(() => import("./pages/Settings"));

function App() {
  return (
    <Suspense fallback={<PageSkeleton />}>
      <Routes>
        <Route path="/dashboard" element={<Dashboard />} />
        <Route path="/settings" element={<Settings />} />
      </Routes>
    </Suspense>
  );
}
// vite.config.ts - manual chunk splitting
export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ["react", "react-dom"],
          charts: ["recharts", "d3"],
          editor: ["@monaco-editor/react"],
        },
      },
    },
  },
});
# Analyze bundle composition
npx vite-bundle-visualizer
npx source-map-explorer dist/assets/*.js

Image Optimization

import Image from "next/image";

function ProductImage({ src, alt }: { src: string; alt: string }) {
  return (
    <Image
      src={src}
      alt={alt}
      width={800}
      height={600}
      sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
      placeholder="blur"
      blurDataURL={generateBlurHash(src)}
      loading="lazy"
    />
  );
}
<!-- Native lazy loading with aspect ratio -->
<img
  src="product.webp"
  alt="Product photo"
  width="800"
  height="600"
  loading="lazy"
  decoding="async"
  fetchpriority="low"
/>

<!-- Preload LCP image -->
<link rel="preload" as="image" href="/hero.webp" fetchpriority="high" />

Caching Headers

function setCacheHeaders(res: Response, options: CacheOptions) {
  if (options.immutable) {
    res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
    return;
  }

  if (options.revalidate) {
    res.setHeader("Cache-Control", `public, max-age=0, s-maxage=${options.revalidate}, stale-while-revalidate=${options.staleWhileRevalidate ?? 86400}`);
    return;
  }

  res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
}

app.use("/assets", (req, res, next) => {
  setCacheHeaders(res, { immutable: true });
  next();
});

app.use("/api", (req, res, next) => {
  setCacheHeaders(res, { revalidate: 60, staleWhileRevalidate: 3600 });
  next();
});

Virtual Lists for Large Data

import { useVirtualizer } from "@tanstack/react-virtual";

function VirtualList({ items }: { items: Item[] }) {
  const parentRef = useRef<HTMLDivElement>(null);

  const virtualizer = useVirtualizer({
    count: items.length,
    getScrollElement: () => parentRef.current,
    estimateSize: () => 50,
    overscan: 5,
  });

  return (
    <div ref={parentRef} style={{ height: "600px", overflow: "auto" }}>
      <div style={{ height: `${virtualizer.getTotalSize()}px`, position: "relative" }}>
        {virtualizer.getVirtualItems().map((virtualRow) => (
          <div
            key={virtualRow.key}
            style={{
              position: "absolute",
              top: 0,
              transform: `translateY(${virtualRow.start}px)`,
              height: `${virtualRow.size}px`,
              width: "100%",
            }}
          >
            <ItemRow item={items[virtualRow.index]} />
          </div>
        ))}
      </div>
    </div>
  );
}

Core Web Vitals Monitoring

import { onCLS, onINP, onLCP } from "web-vitals";

function sendMetric(metric: { name: string; value: number; id: string }) {
  navigator.sendBeacon("/api/vitals", JSON.stringify(metric));
}

onCLS(sendMetric);
onINP(sendMetric);
onLCP(sendMetric);
  • LCP (Largest Contentful Paint): < 2.5s. Preload hero images, optimize server response time.
  • INP (Interaction to Next Paint): < 200ms. Avoid long tasks, use requestIdleCallback.
  • CLS (Cumulative Layout Shift): < 0.1. Set explicit dimensions on images and embeds.

Anti-Patterns

  • Loading all JavaScript upfront instead of code-splitting by route
  • Serving unoptimized images (no WebP/AVIF, no responsive sizes)
  • Missing width and height on images (causes layout shift)
  • Using Cache-Control: no-cache on static assets with content hashes
  • Rendering thousands of DOM nodes instead of virtualizing lists
  • Blocking the main thread with synchronous computation

Checklist

  • Routes lazy-loaded with dynamic import() and Suspense
  • Bundle analyzed and vendor chunks separated
  • Images served in WebP/AVIF with responsive sizes attribute
  • LCP image preloaded with fetchpriority="high"
  • Static assets cached with immutable headers and content hashes
  • Lists with 100+ items use virtualization
  • Core Web Vitals monitored in production (LCP, INP, CLS)
  • No render-blocking resources in the critical path

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Use this skill to make web interfaces more accessible. It provides patterns for semantic HTML, ARIA, keyboard navigation, forms, and color contrast, plus a checklist for evaluating WCAG AA accessibility with assistive technology.

中文简介正在准备中。当前显示英语简介。

  • Making menus and tabs keyboard accessible
  • Improving form labels and error announcements
  • Reviewing contrast and screen reader support
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

Route broad SEO requests to the relevant platform module, such as LinkedIn, GitHub, or a CV. For work spanning several profiles or assets, it helps establish shared facts first and keeps the task focused on the needed context.

中文简介正在准备中。当前显示英语简介。

  • Choose a module for an unclear SEO request
  • Plan SEO work across LinkedIn and GitHub
  • Prepare shared facts before rewriting profile assets
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

Plan REST APIs with consistent resource URLs, HTTP methods, error responses, pagination, filtering, and versioning. It also covers writing an OpenAPI specification, a machine-readable API contract that can guide implementation and validation.

中文简介正在准备中。当前显示英语简介。

  • Choose resource URLs and HTTP methods for an API
  • Plan pagination and filtering for list endpoints
  • Draft an OpenAPI specification before implementation
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

Use this skill to plan or implement web authentication and access control. It covers JWT access and refresh tokens, OAuth2 with PKCE, sessions, and role-based permissions, with code examples and a checklist of common security practices.

中文简介正在准备中。当前显示英语简介。

  • Adding JWT access and refresh tokens to a web app
  • Setting up an OAuth2 login flow with PKCE
  • Restricting routes by user role
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

Build AWS application infrastructure using patterns for Lambda, DynamoDB, S3, and CDK. The examples cover API handlers, data access design, file event processing, and infrastructure settings, helping you shape cloud resources as code and avoid common setup mistakes.

中文简介正在准备中。当前显示英语简介。

  • Design a Lambda API with DynamoDB
  • Plan DynamoDB keys around query needs
  • Process files uploaded to S3
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

Create CI/CD workflows for GitHub Actions or GitLab CI that run validation, tests, builds, and deployments. Examples show job dependencies, caching, matrices, coverage reports, database services, and deployment gates to make automated delivery steps easier to organize.

中文简介正在准备中。当前显示英语简介。

  • Set up lint and test workflow jobs
  • Run tests across operating systems and versions
  • Build and deploy from the main branch
rohitg00/awesome-claude-code-toolkit27492026年5月12日 更新

查看 rohitg00 的全部技能

报告此技能的问题