Files
Daniel Avila 51e3e9cdf4 perf: split components.json to cut dashboard browser payload (#672)
The dashboard is on Cloudflare Pages with a 24h edge cache already in
place, but every island still downloaded the full ~1.9MB index (327KB
gz) — even the sidebars/plugins/collection pages that only need per-type
counts. This splits the index into purpose-built artifacts so the
browser fetches only what each surface needs.

Generator (scripts/generate_components_json.py):
- Decouple the docs and dashboard index writes (they were a byte copy).
  docs/components.json keeps `security` (the legacy site renders it);
  the dashboard index drops both `content` and `security` (unused there)
  → ~13% smaller.
- Emit dashboard/public/counts.json (per-type counts, ~150 bytes),
  components/{type}.json (per-type slices), and search-index.json
  (flat name/description/category/type/path for global search).

Dashboard islands:
- ComponentGrid loads only the active type via fetchComponentsByType,
  re-fetching on type switch (per-type in-memory cache).
- SearchModal (Cmd+K) uses the lighter search-index.json.
- Sidebar + plugins index/detail + collection pages fetch counts.json
  instead of the full index just to read array lengths.
- data.ts gains fetchComponentsByType/fetchSearchIndex (additive);
  fetchComponents() stays for the SSR detail page and Discord bot.

Fix: SendToRepoModal read `match.content` off an index that no longer
carries content, so "Send to repo" produced empty PRs / threw "No
component content found". buildFileMap now pulls each item's content via
fetchComponentContent (the per-component files), which also removes its
full-index fetch.

_headers: cache/CORS blocks for counts.json, components/*, search-index.json.

Payload (gzip on-the-wire): sidebars/plugins/collection 327KB → ~124B;
grid default type (agents) 327KB → 145KB; Cmd+K 327KB → 260KB.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 16:22:46 -04:00

56 lines
1.9 KiB
Plaintext

# Static JSON data — cached 24h at the edge, revalidated on deploy
/components.json
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
# Tiny per-type counts (sidebars, plugins pages) — same 24h cache
/counts.json
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
# Per-type index slices (grid loads only the active type)
/components/*
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
# Flat search index for the global (Cmd+K) search
/search-index.json
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
/component-content/*
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
/plugins.json
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
/trending-data.json
Cache-Control: public, max-age=3600, stale-while-revalidate=300
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
/claude-jobs.json
Cache-Control: public, max-age=3600, stale-while-revalidate=300
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
# Astro hashed assets — immutable forever (hash changes on content change)
/_astro/*
Cache-Control: public, max-age=31536000, immutable
# Security headers — applied to all routes
/*
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Referrer-Policy: strict-origin-when-cross-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains
Permissions-Policy: camera=(), microphone=(), geolocation=()