Optimize

From AkaraChen/aghub · View interactive version

Optimize is an AI agent skill from the GitHub repository AkaraChen/aghub. Diagnoses and fixes 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.

How to use this skill

Skill file

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

Assess Performance Issues

Understand current performance and identify problems:

  1. Measure current state:
  1. Identify bottlenecks:

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

Optimization Strategy

Create systematic improvement plan:

Loading Performance

Optimize Images:

<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"
/>

Reduce JavaScript Bundle:

// Lazy load heavy component
const HeavyChart = lazy(() => import("./HeavyChart"));

Optimize CSS:

Optimize Fonts:

@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 */
}

Optimize Loading Strategy:

Rendering Performance

Avoid Layout Thrashing:

// ❌ 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:

Reduce Paint & Composite:

Animation Performance

GPU Acceleration:

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

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

Smooth 60fps:

Intersection Observer:

// 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:

Framework-agnostic:

Network Optimization

Reduce Requests:

Optimize APIs:

Optimize for Slow Connections:

Core Web Vitals Optimization

Largest Contentful Paint (LCP < 2.5s)

First Input Delay (FID < 100ms) / INP (< 200ms)

Cumulative Layout Shift (CLS < 0.1)

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

Performance Monitoring

Tools to use:

Key metrics:

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

NEVER:

Verify Improvements

Test that optimizations worked:

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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.