astro-optimizer
Skill1 starsChanged 8 days agoMITView on GitHub
Audit and optimize Astro sites (Astro 4, 5, 6 and 7; static or SSR with the node, Netlify, Vercel or Cloudflare adapters) for client JavaScript and island hydration, Core Web Vitals, images and fonts, content collections and build time, route caching, server islands, CSP/env safety, and upgrade fallout, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions a slow Astro site, too much JavaScript, client:load/client:visible/client:only, islands or server islands, hydration, Lighthouse LCP/INP/CLS, astro:assets or Image/Picture, font loading, ViewTransitions/ClientRouter, prefetch, content collections taking forever to build, getStaticPaths, SSR TTFB, route caching, CSP, or upgrading Astro 5 to 6/7 -- even if they never say "audit" or "optimize".
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- architecture-optimizerSkill
- csharp-optimizerSkill
- cpp-optimizerSkill
- c-optimizerSkill
- go-optimizerSkill
- node-service-optimizerSkill
- ruby-optimizerSkill
- rust-optimizerSkill
- docker-optimizerSkill
- kubernetes-optimizerSkill
- terraform-optimizerSkill
- animate-cssSkill
- animejsSkill
- auto-animateSkill
- gsapSkill
- lenisSkill
- magicuiSkill
- motionSkill
- react-moveSkill
- react-springSkill
- react-three-fiberSkill
- theatrejsSkill
- threejsSkill
- optimizer-routerSkill
- bootstrap-optimizerSkill
- pandacss-optimizerSkill
- sass-scss-optimizerSkill
- stylex-optimizerSkill
- tailwindcss-optimizerSkill
- twind-optimizerSkill
- unocss-optimizerSkill
- vanilla-extract-optimizerSkill
- angular-optimizerSkill
- ui-components-optimizerSkill
- nextjsSkill
- node-optimizerSkill
- nuxt-optimizerSkill
- react-optimizerSkill
- remix-optimizerSkill
- solid-optimizerSkill
- svelte-optimizerSkill
- tanstack-start-optimizerSkill
- vue-optimizerSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Run python <skill-dir>/scripts/audit.py <project-root> -- static scan of package.json, astro.config.* and .astro/.ts/.js/.mdx sources for …
- Very specific: line 17
If the user only gave a URL, say a code audit needs the repo.
- Very specific: line 44
Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode.
- Distinctive: line 71
Caching is correctness first: Never let a shared CDN or route rule cache a per-user response.
- Distinctive: line 72
Do not break HTML, SEO or accessibility for speed: Keep semantic markup, real links, alt text, focus handling and error pages.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Astro Optimizer
Audit an Astro codebase, report what is slow or fragile and why, agree a plan with the user, then fix it. Order: evidence, approval, edits. Astro's promise is HTML first and JavaScript only where you ask for it, so the first question is always what is being hydrated that does not need to be. Hydration, caching and CSP changes can alter behavior or security, so nothing is edited before approval.
Workflow
1. Scope (quick)
- Find the project root (
package.jsonwithastro, plusastro.config.*). Record: Astro major, output mode (staticby default, orserver), adapter, integrations, UI framework renderers, content collections,site, Node version and package manager. Ifoutput: 'hybrid'is still present, the project predates Astro 5. - Run
python <skill-dir>/scripts/audit.py <project-root>-- static scan ofpackage.json,astro.config.*and.astro/.ts/.js/.mdxsources for version leftovers, hydration cost, image/font gaps, XSS and cache misuse, with file:line evidence. Use--jsonto post-process. - Classify the pain: slow load (JS/CSS/images/fonts), bad LCP or CLS, slow interactions (heavy islands), slow SSR/TTFB (origin/cache), slow build (collections/images), or code health/upgrade. Ask which hurts if unclear.
- If the user only gave a URL, say a code audit needs the repo; meanwhile collect field data (CrUX/PageSpeed Insights) and do not guess at causes. Read
references/tooling.mdonce to see what can actually be measured here. - Astro sites often contain React/Svelte/Vue islands. Optimize the island boundary here; for component internals inside an island, hand off to the matching framework optimizer.
2. Audit
The script finds cheap leads; you find the rest by reading. Read astro.config.*, the base layout, the home page, the 3-5 most important routes, and every component with a client:* directive. Load only what applies:
| Area | Reference |
| Islands, client directives, hydration, framework components | references/islands-hydration.md |
| Output modes, prerender, server islands, route caching, sessions | references/rendering-caching.md |
| Content collections, live collections, data fetching, build scale | references/content-data.md |
| Images, responsive srcset, fonts, CSS delivery | references/assets-fonts.md |
| Script processing, view transitions, prefetch, bundles, CWV | references/scripts-bundle.md |
| XSS/CSP/secrets, accessibility, types, tests, upgrades | references/safety-quality.md |
| Production measurement and honest reporting | references/tooling.md |
Measure, never guess. Build for production, run it (astro preview or the adapter's server), and measure that. Count islands by directive, inspect transferred JS per island, and check the LCP image and font requests. Dev-server timings mean nothing, and a single Lighthouse run is weaker evidence than field p75 data.
Mark each finding Confirmed (build output, network panel, code evidence) or Suspected (needs measuring).
3. Report
Fill assets/report-template.md, save it as ASTRO_OPTIMIZATION_REPORT.md in the project root, and show the user. Five-line summary, findings table sorted by impact/effort, then per-finding detail (evidence, why it hurts, fix, risk, behavior impact). Group near-duplicates.
4. Plan -- then stop for approval
Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode; if unavailable show it in chat and wait for an explicit "go". Structure:
- Quick wins --
client:loadtoclient:visible/client:idle, delete client directives from components that render static markup, use<Image>/<Picture>withlayoutand real dimensions, preload the one real font, enable prefetch, remove unused integrations, add cache headers. Low risk. - Structural -- replace a framework island with
.astro+<script>/custom element, split a header island into a small cart island, move personalization into aserver:deferisland, prerender routes that do not need request data, move ad-hoc content globs to collections, adopt route caching. Name each behavior change. - Heavy -- Astro 5 to 6 to 7 upgrade, removing a UI framework or adapter, changing image service, adopting view transitions site-wide. Separately approved. Each step: files touched, expected effect, how to verify, how to roll back.
4b. Experimental gate (ask before enabling)
Astro's experimental flags (clientPrerender, incrementalBuild, parallelPrerender, svgOptimization, collectionStorage, staticRedirectPage, plus adapter experimental CDN cache providers) can help, but they may change between minors, need host support, or change output. Never enable them as part of a "quick win": list only the ones that fit this project in an Experimental candidates section with benefit, risk, rollback and the version that introduced them, then ask which, if any, the user wants. Declined flags stay out of the plan.
5. Fix
Only approved items, in small groups. After each: npx astro check (if installed), the project's lint and tests, then npx astro build. A break must trace to one change. Do not mix an upgrade with optimization edits. If an approved change turns out to expose per-user data to a shared cache, or to remove interactivity users had, stop and ask.
6. Verify and wrap up
Re-measure the same scenario: transferred JS per island, island count by directive, LCP/INP/CLS on a production build, build wall time and page count, and SSR TTFB for server-rendered routes. State plainly what could not be measured. End with deferred items and one suggested next step.
Principles
- Ship less JavaScript. An island is a cost, not a feature. Every
client:*directive must earn its framework runtime. - Choose the cheapest directive that keeps the interaction.
client:visiblebelow the fold,client:idlefor non-urgent,client:loadonly for above-the-fold interactivity,client:onlyonly when SSR is impossible. - Static by default, dynamic by exception.
prerender = falseis a decision with a hosting and cache cost; keep it off routes that can be built. - Server islands beat making the whole page dynamic. Defer the avatar, cart count or price, cache the shell.
- Content collections beat ad-hoc globs for structured content, and build-time beats request-time unless freshness is the point.
- Images and fonts decide LCP and CLS. A hero image in
public/with nowidth/heightis a finding, not a style choice. - Caching is correctness first. Never let a shared CDN or route rule cache a per-user response; state the staleness trade-off for every cache change.
- Do not break HTML, SEO or accessibility for speed. Keep semantic markup, real links, alt text, focus handling and error pages.
- Docs move. Astro 5, 6 and 7 differ (removed
Astro.glob/ViewTransitions, strict Rust compiler, new Markdown pipeline). Check the docs for the version inpackage.json, not memory.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

