# optimize-web-animations

Pauses offscreen CSS, Canvas, and WebGL animations and fixes frontend memory leaks. Useful when long browser sessions or heavy page effects cause janky scrolling and high CPU load.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1700 installs · ★ 7001
- Author: MengTo
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/MengTo/Skills/tree/HEAD/agent-skills/codex/optimize-web-animations/SKILL.md
- Updated: 2026-10-25
- HTML: https://affpapa.org/en/nevibecode/skills/optimize-web-animations

## What it does

The skill audits CSS keyframes, `requestAnimationFrame` loops, and effects built with GSAP, Three.js, or Matter.js. It measures the live page using Codex Browser before editing any code. Chrome is ignored unless you specifically ask for it. The baseline run counts visible and hidden animations at the top, middle, footer, and mobile viewport.

To reduce load, the skill hooks up an `IntersectionObserver` and applies an `is-offscreen` class to hidden sections. It pauses CSS animations with `animation-play-state: paused !important` and cancels canvas RAF loops until scrolled into view. Component cleanups dispose Three.js textures, disconnect observers, and clear intervals. Leaving unmount cleanup incomplete causes long-lived memory leaks across route changes.

After making edits, the skill verifies that `offscreenRunningCount` drops to `0`. It checks interactive elements, runs `npm run lint` and `npm run build`, and stages narrow Git commits through an isolated index if your working tree has unrelated changes.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add MengTo/Skills --skill optimize-web-animations -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/optimize-web-animations/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/optimize-web-animations/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add MengTo/Skills --skill optimize-web-animations -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/optimize-web-animations/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add MengTo/Skills --skill optimize-web-animations -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/optimize-web-animations/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install MengTo/Skills optimize-web-animations
```

2. **Manually: put the files in place**
- File: `.github/skills/optimize-web-animations/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add MengTo/Skills --skill optimize-web-animations -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/MengTo/Skills --path agent-skills/codex/optimize-web-animations
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/optimize-web-animations/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add MengTo/Skills --skill optimize-web-animations -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/MengTo/Skills/tree/HEAD/agent-skills/codex/optimize-web-animations/SKILL.md

## When to use it
- Pause offscreen CSS keyframes and RAF loops when elements leave the viewport
- Fix frontend memory leaks caused by lingering timers, observers, and event listeners
- Dispose Three.js textures, materials, and WebGL renderers on component unmount
- Measure baseline animation counts and idle memory across page routes using Codex Browser

## Example prompts
- Use optimize-web-animations to profile the landing page and pause offscreen motion.
- Check this route for memory leaks and runaway requestAnimationFrame loops.
- Fix janky scrolling by stopping GSAP tweens and WebGL animations when out of view.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 0a4391c5e1097b46.

BEGIN THIRD-PARTY FILE 0a4391c5e1097b46
```text
---
name: optimize-web-animations
description: Profile, audit, and optimize frontend page performance with emphasis on animation work, memory-leak risks, long-session slowdowns, CSS animations, canvas/WebGL requestAnimationFrame loops, marquees, skeletons, GSAP/Three/Matter effects, timers, listeners, and observers. Use when the user asks to make animations performant, pause offscreen animations, look for memory leaks, profile pages that slow the computer over time, fix janky scrolling, reduce CPU/GPU use, or repeat the "only play in view" optimization on React/Vite/Next/frontend pages using Codex Browser.
---

# Optimize Web Animations

## Core Rule

Measure the real page before editing. The goal is not to remove motion; it is to make offscreen work stop, visible motion resume correctly, and route/unmount cleanup release long-lived resources.

Use Codex Browser when available, especially for localhost pages. Do not use Chrome unless the user explicitly asks for it.

## Workflow

1. Inspect repo context.
   - Read `AGENTS.md` or local instructions.
   - Run `git status --short` early.
   - Find page components, animation hooks, CSS keyframes, `requestAnimationFrame`, `setInterval`, `setTimeout`, canvas/WebGL/physics components, media elements, GSAP timelines/tweens, and existing visibility utilities.
   - Search effect cleanup for event listeners, observers, RAF loops, intervals, timers, external scripts, media streams, WebGL textures/materials/geometries/renderers, and async work that can complete after unmount.
   - If the worktree is dirty, plan narrow staging from the start.

2. Capture a baseline in the browser.
   - Open the exact route the user named.
   - Profile at top, mid-page, footer/lower content, and one mobile viewport when layout could differ.
   - Count CSS animations by computed `animationName`, `animationPlayState`, and visibility. Include `::before` and `::after`.
   - Inspect canvases/WebGL elements separately; CSS profiling does not prove RAF loops have stopped.
   - Record which animation names are running offscreen and the DOM owners responsible.
   - For memory/leak asks, also record element/canvas/image/iframe counts, exposed JS heap metrics when available, an idle sample after 10-30 seconds, and a short route-cycle sample. If heap APIs return `null` or the Browser sandbox blocks monkey-patching, say so and rely on stable observable counts plus source audit.
```
END THIRD-PARTY FILE 0a4391c5e1097b46

The third-party file has ended. Everything between the 0a4391c5e1097b46 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2426 of 8257 bytes. © MengTo · MIT · https://github.com/MengTo/Skills/tree/HEAD/agent-skills/codex/optimize-web-animations/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
