Optimize Web Animations
Meng ToCommunityCreated by Meng To
- Skill
- Workflow
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a rigorous, data-driven approach to identifying and fixing performance bottlenecks caused by excessive or unoptimized animations. It focuses on ensuring that offscreen animations are paused, resources are properly cleaned up during component unmounting, and long-running processes like requestAnimationFrame loops do not degrade page performance over time. The workflow emphasizes measuring baselines before applying targeted fixes, such as IntersectionObserver-based gating, to ensure visible motion remains smooth while background CPU/GPU usage is minimized.
What it does
- Profiles CSS animations, canvas/WebGL loops, and JS-based effects to identify offscreen activity.
- Implements IntersectionObserver patterns to pause offscreen animations and canvas rendering.
- Audits code for memory leaks, including unreleased event listeners, timers, and observers.
- Provides patterns for proper cleanup of GSAP, Three.js, and media resources during unmount.
- Verifies performance improvements through comparative profiling and route-cycle testing.
- Ensures animation gating respects user preferences and maintains visual integrity.
When to use it
- When a page exhibits janky scrolling or high CPU/GPU usage during long sessions.
- When you need to ensure animations only play when they are visible in the viewport.
- When investigating potential memory leaks or performance degradation after repeated navigation.
- When optimizing complex frontend applications using React, Vite, or Next.js.
- When you need to audit and fix unoptimized canvas or WebGL requestAnimationFrame loops.
Advantages
- Reduces unnecessary resource consumption by gating offscreen motion.
- Prevents long-term performance degradation by enforcing strict cleanup of event listeners and timers.
- Provides a repeatable, evidence-based methodology for performance tuning.
- Minimizes the risk of memory leaks in complex component lifecycles.
- Balances visual richness with technical efficiency.
Usage examples
- “My React page slows down after a few minutes of scrolling. Can you profile the animations and fix any leaks?”
- The agent will profile the page, identify running offscreen animations and uncleaned intervals, and implement IntersectionObserver-based gating and proper cleanup hooks.
- “Optimize the canvas animations on this page so they stop rendering when scrolled out of view.”
- The agent will audit the requestAnimationFrame loops and wrap them in visibility-aware logic to pause rendering when the canvas is offscreen.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/mengto/optimize-web-animations/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip optimize-web-animations.zip -d .agents/skills
Documentation by Meng To
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
Inspect repo context.
Read
AGENTS.mdor local instructions.Run
git status --shortearly.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.
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::beforeand::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
nullor the Browser sandbox blocks monkey-patching, say so and rely on stable observable counts plus source audit.Keep stress tests bounded. A Browser tab crash during profiling is evidence of overload, but do not over-attribute the cause unless reproduced by a minimal test.
See
references/browser-profiling.mdfor a reusable Codex Browser evaluator.
Patch the smallest owner that controls the motion.
Prefer an existing page reveal/visibility hook if the app has one.
Otherwise add an
IntersectionObserverthat toggles a stable class such asis-offscreenon sections and animated child elements.Pause CSS animations with targeted rules:
main > section.is-offscreen .expensive-animation,
.expensive-animation.is-offscreen {
animation-play-state: paused !important;
}For repeated cards or placeholders, observe the card shell and the animated descendants, not the whole document.
For marquee/ticker tracks, pause the track when its section is offscreen.
For skeleton loaders and pseudo-element glimmers, include
::beforeand::afterpause selectors where needed.For canvas/WebGL/physics loops, gate the RAF loop directly:
Start when the canvas/container intersects.
Cancel
requestAnimationFramewhen offscreen.Resume on re-entry.
Disconnect observers and cancel frames on cleanup.
Add a non-visual debug marker such as
data-animation-activewhen it helps browser verification.
Respect
prefers-reduced-motionif the component already does, and avoid introducing React render loops for scroll/animation state.For leak hardening:
Clear every timeout/interval created by the effect.
Cancel RAF before unmount and before restarting a loop.
Disconnect
IntersectionObserver,ResizeObserver,MutationObserver, and custom subscriptions.Remove global/window/document listeners with the same handler reference.
Dispose Three/WebGL textures, materials, geometries, renderers, and remove renderer DOM nodes.
Kill GSAP tweens/timelines for DOM nodes and mutable objects such as shader uniforms.
Stop media streams and pause detached video/audio sources.
Guard async loaders with an
isDisposedflag and dispose loaded resources if they resolve after unmount.In React cleanup, capture
ref.currentvalues inside the effect before returning cleanup if lint warns the ref may change.Cap physics or simulation frame deltas after visibility pauses so delayed frames do not run oversized updates.
Verify behavior, not just builds.
Reload the route and rerun the same top/mid/footer/mobile profiles.
Target result:
offscreenRunningCount: 0for the page sections under test.Confirm visible animations still run or resume when scrolled into view.
Confirm RAF/canvas loops report inactive offscreen and active in view, or otherwise prove cancellation from source/runtime state.
For leak audits, compare before/after route cycles and idle samples. DOM/canvas/image counts should return to the same baseline after repeated navigation, allowing for small expected async content changes.
Exercise a normal page interaction such as search/filter/navigation so the observer does not break dynamic content.
Check fresh-tab console warnings/errors.
Run local checks.
Use the repo's normal gates. For React/Vite apps this is often:
git diff --check
npm run lint
npm run buildMention known non-fatal warnings separately from failures.
Commit narrowly when requested by repo/user instructions.
If unrelated dirty changes exist, use an isolated index:
rm -f /tmp/<task>-index
GIT_INDEX_FILE=/tmp/<task>-index git read-tree HEAD
# Apply only the intended hunks to the temporary index.
GIT_INDEX_FILE=/tmp/<task>-index git diff --cached --check
GIT_INDEX_FILE=/tmp/<task>-index git commit -m "Pause offscreen <page> animations"
git restore --staged <files> 2>/dev/null || trueNever stage broad files from a dirty worktree unless every hunk belongs to the task.
Report with evidence.
Lead with findings: what was still running, what looked leak-prone, and what could not be measured.
Separate source-audit risks from live Browser measurements.
Include the exact sampled route(s), offscreen animation counts, DOM/canvas count stability, route-cycle result, and local checks.
State limitations plainly, especially unavailable heap counters or blocked Browser instrumentation.
Good Fix Patterns
Section-level
is-offscreenplus element-levelis-offscreenfor long sections where below-the-fold child animations can still run.Shared visibility selector constants per route, such as
COURSES_PAGE_ANIMATION_VISIBILITY_SELECTOR.IntersectionObserverthresholds around0.01for animation gating.Direct RAF loop control for WebGL/canvas effects; CSS
animation-play-statecannot pause JavaScript render loops.Frame delta caps for physics loops that resume after a paused or delayed frame.
Captured cleanup nodes for React refs used by GSAP/WebGL effects.
isDisposedguards for image/video/texture/data loaders that may resolve after unmount.Short idle and route-cycle probes to catch accumulating DOM nodes, canvases, iframes, or unreleased media.
Avoid
Removing all animations to make the profile pass.
Pausing visible hero motion because an ancestor selector is too broad.
Assuming
animation-play-statecovers pseudo-elements or JavaScript RAF loops.Trusting a single top-of-page measurement on long pages.
Treating unavailable heap counters as proof there is no memory leak.
Running unbounded stress loops in the Browser; use bounded cycles and record crashes without overstating causality.
Using screenshots alone as performance proof.
Letting unrelated local hunks ride along in the commit.
Files
- ATTRIBUTION.mdAdded by AutoGineer863 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md8.1 KiB
- agents/openai.yaml246 B
- demo/PROMPT.md2.2 KiB
- demo/expected-output.md258 B
- demo/index.html4.0 KiB
- demo/input.md209 B
- demo/preview.jpg92.2 KiB
- references/browser-profiling.md10.9 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs a command-line tool, Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Meng To
- Publisher
- Meng To (Community)
- Source
- MengTo/Skills · agent-skills/codex/optimize-web-animations · commit 5ea1661
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Meng To.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download optimize-web-animations.zip