К основному содержанию
скилл CX Codex

optimize · aladicf — скилл для Claude Code: диагностика и ускорение UI

Скилл находит, почему интерфейс тормозит: медленная загрузка, лаги анимаций, тяжёлые картинки, раздутый бандл. Запускается, когда вы жалуетесь на «тормозит».

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add aladicf/better-web-ui --skill optimize -a claude-code
Открыть на GitHub

Что делает optimize

Скилл ведёт агента по шагам: сначала измерить текущее состояние, потом искать узкие места, потом чинить. В замеры входят Core Web Vitals (LCP, INP, CLS), время до интерактивности, задержка отклика на фильтры, поиск, сохранение и автодополнение, размеры JS, CSS и картинок, частота кадров, память, сетевые запросы. Отдельно скилл требует измерить до и после — преждевременная оптимизация тратит время впустую.

Дальше идёт набор приёмов. Картинки: WebP и AVIF с фолбэком через picture, srcset, ленивая загрузка, сжатие. Бандл: code splitting, tree shaking, динамические импорты. Шрифты: font-display: swap, сабсеттинг через pyftsubset или subfont, unicode-range для латиницы и кириллицы отдельными файлами. Для отклика на действия скилл ссылается на порог Доэрти: подтверждение в пределах примерно 100 мс, разрешение взаимодействия — около 400 мс, вместо пустого спиннера скелетон или оптимистичный UI.

Перед началом работы скилл требует загрузить $frontend-design и пройти его протокол сбора контекста, а если контекста ещё нет — сначала $setup. Ещё нужно назвать целевые устройства, ограничения по производительности и какие именно действия кажутся медленными. Для длинных списков скилл советует TanStack Virtual, но только если в проекте ещё нет своей виртуализации: чужой слой он сохраняет.

Какие задачи решает

  • понять, почему страница долго грузится
  • убрать дёргание анимаций и просадку кадров
  • сократить размер JS-бандла
  • подобрать форматы и размеры картинок
  • ускорить отклик на фильтры и поиск

Примеры запросов агенту

  • /optimize главная страница тормозит при загрузке
  • /optimize список товаров лагает при скролле
  • /optimize проверь размер бандла и шрифты

Как установить optimize

1Через Skills CLI (Vercel)

npx skills add aladicf/better-web-ui --skill optimize -a claude-code

2Вручную: положить файлы

~/.claude/skills/optimize/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/optimize/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о optimize

Как установить optimize в Claude?

Выполните npx skills add aladicf/better-web-ui --skill optimize -a claude-code. Скилл встанет в ~/.claude/skills/optimize/SKILL.md.

Что делает optimize?

Диагностирует и чинит проблемы производительности интерфейса: скорость загрузки, рендеринг, анимации, картинки, размер бандла. Агент сначала измеряет, потом оптимизирует.

Что нужно подготовить до запуска?

Скилл требует загрузить $frontend-design и пройти его протокол сбора контекста, а без контекста — сначала $setup. Также назовите целевые устройства, ограничения и медленные взаимодействия.

Исходный текст

SKILL.md · MIT
---
name: optimize
description: Diagnose and fix UI performance across loading speed, rendering, animations, images, and bundle size. Use when the user mentions slow, laggy, janky, performance, bundle size, load time, or wants a faster, smoother experience.
metadata:
  argument-hint: "[target]"
---

Identify and fix performance issues to create faster, smoother user experiences.

Consult the [image treatment](../frontend-design/reference/image-treatment.md) when image performance problems intersect with screenshot sizing, icon scaling, cropping strategy, or user-uploaded media handling.
Consult the [text layout prediction](../frontend-design/reference/text-layout-prediction.md) when performance issues come from measuring many wrapped text blocks, variable-height virtualization, repeated resize relayouts, or hot-path DOM reads like `offsetHeight` / `getBoundingClientRect()` for text-heavy UI.
Consult the [core web vitals reference](../frontend-design/reference/core-web-vitals.md) when the optimization work focuses on LCP, INP, or CLS specifically and needs deeper subpart breakdowns or field-vs-lab measurement guidance.
When a project needs virtualization for very long lists and the stack is still open, prefer TanStack Virtual as the default headless virtualization layer across the supported React, Vue, Angular, Solid, and Svelte ecosystems. If the project already uses another virtualization layer, preserve that first.

## MANDATORY PREPARATION

Users start this workflow with `/optimize`. Once this skill is active, load $frontend-design — it contains design principles, anti-patterns, and the **Context Gathering Protocol**. Follow that protocol before proceeding — if no design context exists yet, you MUST load $setup first. Additionally gather: the target devices, performance constraints, and which user interactions feel slow.

## Assess Performance Issues

Understand current performance and identify problems:

1. **Measure current state**:
   - **Core Web Vitals**: LCP, FID/INP, CLS scores
   - **Load time**: Time to interactive, first contentful paint
  - **Interaction latency**: Response time for filters, search, save, open-panel, autocomplete, and other repeated actions
   - **Bundle size**: JavaScript, CSS, image sizes
   - **Runtime performance**: Frame rate, memory usage, CPU usage
   - **Network**: Request count, payload sizes, waterfall

2. **Identify bottlenecks**:
   - What's slow? (Initial load? Interactions? Animations?)
   - What's causing it? (Large images? Expensive JavaScript? Layout thrashing?)
   - How bad is it? (Perceivable? Annoying? Blocking?)
  - Who's affected? (All users? Narrow-layout users? Slow connections?)

**CRITICAL**: Measure before and after. Premature optimization wastes time. Optimize what actually matters.

## Optimization Strategy

Create systematic improvement plan:

### Doherty Threshold for Interaction Speed

Routine interactions should preserve flow. Aim for users to see acknowledgment immediately and, when possible, feel the interaction resolve within roughly **400ms**.

When work will exceed that window:
- show instant feedback within ~100ms (pressed, active, loading, optimistic state)
- stream or reveal partial content early instead of waiting for everything
- prefetch likely next screens or data for common paths
- prefer skeletons, optimistic UI, and progressive rendering over blank waits and generic spinners

**Don't** rely on a spinner as the main experience for high-frequency actions if the interface could instead acknowledge intent and keep momentum alive.

### Loading Performance

**Optimize Images**:
- Use modern formats (WebP, AVIF)
- Proper sizing (don't load 3000px image for 300px display)
- Lazy loading for below-fold images
- Responsive images (`srcset`, `picture` element)
- Compress images (80-85% quality is usually imperceptible)
- Use CDN for faster delivery

```html
<img
  src="hero.webp"
  srcset="hero-400.webp 400w, hero-800.webp 800w, hero-1200.webp 1200w"
  sizes="(max-width: 400px) 400px, (max-width: 800px) 800px, 1200px"
  loading="lazy"
  alt="Hero image"
/>
```

**Modern image format strategy (AVIF and WebP)**:

AVIF typically delivers 30-50% smaller files than WebP at equivalent visual quality. WebP has broader baseline support. Use both with fallback:

```html
<picture>
  <source srcset="hero.avif" type="image/avif">
  <source srcset="hero.webp" type="image/webp">
  <img src="hero.jpg" alt="Hero image" loading="lazy">
</picture>
```

Practical rules:
- generate AVIF for hero images, large backgrounds, and photo-heavy galleries where the size savings matter most
- keep WebP as the fallback for broader browser coverage
- do not serve AVIF for tiny icons or simple graphics where encoding overhead outweighs savings
- use an image CDN that handles format negotiation automatically when possible
- test AVIF decode speed on low-end devices; the format is smaller but can be slower to decode than WebP

**Reduce JavaScript Bundle**:
- Code splitting (route-based, component-based)
- Tree shaking (remove unused code)
- Remove unused dependencies
- Lazy load non-critical code
- Use dynamic imports for large components

```javascript
// Lazy load heavy component
const HeavyChart = lazy(() => import('./HeavyChart'));
```

**Optimize CSS**:
- Remove unused CSS
- Critical CSS inline, rest async
- Minimize CSS files
- Use CSS containment for independent regions

**Optimize Fonts**:
- Use `font-display: swap` or `optional`
- Subset fonts (only characters you need)
- Preload critical fonts
- Use system fonts when appropriate
- Limit font weights loaded

```css
@font-face {
  font-family: 'CustomFont';
  src: url('/fonts/custom.woff2') format('woff2');
  font-display: swap; /* Show fallback immediately */
  unicode-range: U+0020-007F; /* Basic Latin only */
}
```

**Font subsetting strategy**:

Subsetting removes unused glyphs and dramatically reduces file size. A full Latin font may be 200KB; the same font subsetted to Basic Latin can be 20-30KB.

Approaches:
- **Static subsetting**: generate separate font files per language or script (Latin, Cyrillic, CJK) and serve only what the page needs via `unicode-range`
- **Dynamic subsetting**: use a service like Google Fonts or a self-hosted subsetter that generates slices on demand
- **Critical glyph subsetting**: for above-the-fold hero text, subset to only the characters used in the headline and preload that file

```css
/* Latin-only subset for body text */
@font-face {
  font-family: 'CustomFont';
  src: url('/fonts/custom-latin.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+0020-007F, U+00A0-00FF;
}

/* Extended subset for other scripts, loaded only when needed */
@font-face {
  font-family: 'CustomFont';
  src: url('/fonts/custom-cyrillic.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+0400-04FF;
}
```

Tools for subsetting:
- `pyftsubset` (fonttools) for precise manual subsetting
- `subfont` for automatic subsetting at build time
- `glyphhanger` for extracting only the glyphs used in your HTML/CSS

**Critical CSS extraction**:

Extract the CSS needed for above-the-fold content and inline it in the HTML `<head>`. Load the remaining CSS asynchronously.

Why it matters:
- render-blocking CSS is often the biggest contributor to slow First Contentful Paint
- inlining critical CSS eliminates the network request for the initial view
- non-critical CSS can load after the page is interactive

How to implement:
- use `critical` (npm package) or `Penthouse` to extract above-the-fold CSS automatically
- or identify critical CSS manually: header styles, hero layout, initial typography, and above-the-fold component styles
- inline the critical CSS in a `<style>` tag in the `<head>`
- load the full stylesheet asynchronously:

```html
<head>
  <style>
    /* Critical CSS inlined here */
  </style>
  <link rel="preload" href="/styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
  <noscript><link rel="stylesheet" href="/styles.css"></noscript>
</head>
```

Caveats:
- do not inline more than ~14KB of CSS (gzippped) to stay within single TCP round-trip budgets
- critical CSS must be kept in sync with the actual above-the-fold content; regenerate it when layouts change
- for SPAs, consider route-level critical CSS rather than page-level

**Optimize Loading Strategy**:
- Critical resources first (async/defer non-critical)
- Preload critical assets
- Prefetch likely next pages
- Service worker for offline/caching
- HTTP/2 or HTTP/3 for multiplexing

**Container queries for component-level responsiveness**:

Container queries let components adapt to their own container size rather than the viewport. This reduces the need for page-wide breakpoint overrides and makes components more reusable.

When to use:
- a component appears in multiple contexts (sidebar, main column, modal)
- the component layout should depend on the space it has, not the device width
- you want to reduce breakpoint proliferation at the page level

Consult the [container queries reference](../frontend-design/reference/container-queries.md) for syntax, practical patterns, and browser support.

Performance note:
- container queries add minimal runtime cost; they run on the compositor like media queries
- prefer `container-type: inline-size` over `size` unless you genuinely need both dimensions
- avoid creating containment contexts on every element; only where the component needs to query its container

### Rendering Performance

**Avoid Layout Thrashing**:
```javascript
// ❌ Bad: Alternating reads and writes (causes reflows)
elements.forEach(el => {
  const height = el.offsetHeight; // Read (forces layout)
  el.style.height = height * 2; // Write
});

// ✅ Good: Batch reads, then batch writes
const heights = elements.map(el => el.offsetHeight); // All reads
elements.forEach((el, i) => {
  el.style.height = heights[i] * 2; // All writes
});
```

**Optimize Rendering**:
- Use CSS `contain` property for independent regions
- Minimize DOM depth (flatter is faster)
- Reduce DOM size (fewer elements)
- Use `content-visibility: auto` for long lists
- Virtual scrolling for very long lists — prefer TanStack Virtual when the architecture is still open; preserve the existing virtualization stack first if the project already has one
- For text-heavy variable-height lists or cards, prefer predictive text measurement over repeated live DOM height reads when wrapping is the real bottleneck

**Reduce Paint & Composite**:
- Use `transform` and `opacity` for animations (GPU-accelerated)
- Avoid animating layout properties (width, height, top, left)
- Use `will-change` sparingly for known expensive operations
- Minimize paint areas (smaller is faster)

### Animation Performance

**GPU Acceleration**:
```css
/* ✅ GPU-accelerated (fast) */
.animated {
  transform: translateX(100px);
  opacity: 0.5;
}

/* ❌ CPU-bound (slow) */
.animated {
  left: 100px;
  width: 300px;
}
```

**Smooth 60fps**:
- Target 16ms per frame (60fps)
- Use `requestAnimationFrame` for JS animations
- Debounce/throttle scroll handlers
- Use CSS animations when possible
- Avoid long-running JavaScript during animations

**Intersection Observer**:
```javascript
// Efficiently detect when elements enter viewport
const observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      // Element is visible, lazy load or animate
    }
  });
});
```

### React/Framework Optimization

**React-specific**:
- Use `memo()` for expensive components
- `useMemo()` and `useCallback()` for expensive computations
- Virtualize long lists
- Code split routes
- Avoid inline function creation in render
- Use React DevTools Profiler

**Framework-agnostic**:
- Minimize re-renders
- Debounce expensive operations
- Memoize computed values
- Lazy load routes and components

### Network Optimization

**Reduce Requests**:
- Combine small files
- Use SVG sprites for icons
- Inline small critical assets
- Remove unused third-party scripts

**Optimize APIs**:
- Use pagination (don't load everything)
- GraphQL to request only needed fields
- Response compression (gzip, brotli)
- HTTP caching headers
- CDN for static assets

**Optimize for Slow Connections**:
- Adaptive loading based on connection (navigator.connection)
- Optimistic UI updates
- Request prioritization
- Progressive enhancement

## Core Web Vitals Optimization

### Largest Contentful Paint (LCP < 2.5s)
- Optimize hero images
- Inline critical CSS
- Preload key resources
- Use CDN
- Server-side rendering

### First Input Delay (FID < 100ms) / INP (< 200ms)
- Break up long tasks
- Defer non-critical JavaScript
- Use web workers for heavy computation
- Reduce JavaScript execution time

### Cumulative Layout Shift (CLS < 0.1)
- Set dimensions on images and videos
- Don't inject content above existing content
- Use `aspect-ratio` CSS property
- Reserve space for ads/embeds
- Avoid animations that cause layout shifts

```css
/* Reserve space for image */
.image-container {
  aspect-ratio: 16 / 9;
}
```

## Performance Monitoring

**Tools to use**:
- Chrome DevTools (Lighthouse, Performance panel)
- WebPageTest
- Core Web Vitals (Chrome UX Report)
- Bundle analyzers (webpack-bundle-analyzer)
- Performance monitoring (Sentry, DataDog, New Relic)

**Key metrics**:
- LCP, FID/INP, CLS (Core Web Vitals)
- Time to Interactive (TTI)
- First Contentful Paint (FCP)
- Total Blocking Time (TBT)
- Bundle size
- Request count

**IMPORTANT**: Measure on real devices with real network conditions. Desktop Chrome with fast connection isn't representative.

**NEVER**:
- Optimize without measuring (premature optimization)
- Sacrifice accessibility for performance
- Break functionality while optimizing
- Use `will-change` everywhere (creates new layers, uses memory)
- Lazy load above-fold content
- Optimize micro-optimizations while ignoring major issues (optimize the biggest bottleneck first)
- Forget about constrained-browser performance (often slower hardware, tighter CPU budgets, slower connections)

## Verify Improvements

Test that optimizations worked:

- **Before/after metrics**: Compare Lighthouse scores
- **Real user monitoring**: Track improvements for real users
- **Different devices**: Test on low-power touch-capable hardware and mainstream laptop/desktop browsers
- **Slow connections**: Throttle to 3G, test experience
- **No regressions**: Ensure functionality still works
- **User perception**: Does it *feel* faster?

Remember: Performance is a feature. Fast experiences feel more responsive, more polished, more professional. Optimize systematically, measure ruthlessly, and prioritize user-perceived performance.

© aladicf · MIT · aladicf/better-web-ui

Похожие скиллы

Всё по теме «Фронтенд и UI» →

Сначала — optimize от других авторов.

optimize marketcalls Генерирует Python-скрипты для перебора параметров торговых стратегий на VectorBT, строит тепловые карты Plotly и сверяет результаты с бенчмарком NIFTY. CX Codex +1 2 300установок web-performance-optimization davila7 Скилл для Claude, который помогает разобрать, почему сайт грузится медленно, и по шагам убрать узкие места. 3 490установок auditing-performance spencerpauly Скилл проводит аудит производительности приложения: размер бандла, рендеринг, запросы к базе и Core Web Vitals. Пригодится, когда страница грузится долго или интерфейс тормозит. CX Codex +1 476установок frontend-react-best-practices sergiodxa Скилл с 33 правилами по оптимизации React: меньше лишних ре-рендеров, аккуратнее бандл, чище композиция компонентов. Пригодится при написании и рефакторинге компонентов. CX Codex +1 1 200установок core-web-vitals web-quality-skills Скилл для оптимизации Core Web Vitals: сначала измеряет, потом правит LCP, INP и CLS. Полезен, когда страница тормозит или прыгает вёрстка. CX Codex +1 32 000установок loading-sequence patterns.dev Скилл объясняет агенту, в каком порядке грузить CSS, шрифты, JS и картинки, чтобы страница проходила Core Web Vitals. CX Codex +1 1 500установок web-performance-audit secondsky Скилл для аудита скорости страниц: снимает метрики Core Web Vitals, ищет узкие места и подсказывает, что чинить. Пригодится, когда LCP или CLS вылезают за норму. CX Codex +1 526установок

Из того же набора22

colorize Скилл для ИИ-кодинга, который добавляет цвет в слишком серые интерфейсы: семантику состояний, акценты и цветовую иерархию. Пригодится, когда макет выглядит безжизненно. CX Codex +1 551установок harden Прогоняет интерфейс через крайние случаи: длинный текст, ошибки сети, RTL, пустые состояния. Полезен перед выкаткой в прод. CX Codex +1 539установок distill Скилл убирает из UI лишние элементы, опции и функции, оставляя главное. Пригодится, когда экран перегружен контролами и непонятно, что важнее. CX Codex +1 548установок clarify Правит подписи, ошибки, пустые состояния и CTA, чтобы пользователь понимал, что происходит и что делать дальше. CX Codex +1 533установок bolder Скилл для тех случаев, когда интерфейс выглядит слишком безопасно и безлико. Разбирает, что именно делает дизайн скучным, и усиливает его. CX Codex +1 535установок delight Добавляет радость и характер в интерфейс: успешные состояния, пустые экраны, загрузку, ховеры. Для случаев, когда базовая вёрстка уже работает. CX Codex +1 523установок quieter Скилл для ИИ-кодинга, который снижает насыщенность, контраст и визуальный шум в интерфейсе, сохраняя иерархию и характер. Пригодится, когда структура уже нормальная, но выглядит крикливо. CX Codex +1 513установок onboard Помогает спроектировать первый запуск продукта: что показать новичку, в каком порядке и как довести его до первого результата. CX Codex +1 521установок

Спонсоры проекта

Компании, которые помогают держать аналитику открытой