Skip to content

fix: prevent CF caching SPA HTML + Polymarket bandwidth optimization#1058

Merged
koala73 merged 2 commits intomainfrom
worktree-declarative-gliding-bird
Mar 5, 2026
Merged

fix: prevent CF caching SPA HTML + Polymarket bandwidth optimization#1058
koala73 merged 2 commits intomainfrom
worktree-declarative-gliding-bird

Conversation

@koala73
Copy link
Owner

@koala73 koala73 commented Mar 5, 2026

Summary

  • Fix CF 404s on deploy: Apply no-cache, no-store, must-revalidate headers to ALL SPA routes in vercel.json (same regex as rewrite rule). Previously only / and /index.html had no-cache — SPA routes like /map, /dashboard etc. got default caching, so CF served stale HTML referencing old content-hashed bundles → 404 after deploy.
  • Reduce Polymarket bandwidth ~95%: Add server-side aggregation via Railway seed script (seed-prediction-markets.mjs) that fetches all 14 Polymarket tags once every 15 min and writes aggregated results to Redis. Client now uses 3-strategy waterfall: bootstrap hydration → single RPC → legacy fan-out fallback. Eliminates 11 parallel relay requests per user per poll cycle.

Changes

  • vercel.json — SPA-wide no-cache headers (prevents CF from caching HTML)
  • scripts/seed-prediction-markets.mjs — new Railway cron seed script
  • api/bootstrap.js — add predictions key to bootstrap hydration
  • server/worldmonitor/prediction/v1/list-prediction-markets.ts — read bootstrap key first
  • src/services/prediction/index.ts — bootstrap → RPC → fan-out waterfall

Test plan

  • Hard-refresh all domains after CF purge — no 404s
  • Future deploys don't cause bundle 404s (CF bypass rule + no-cache headers)
  • Prediction panel loads from bootstrap data on page load
  • Add seed-prediction-markets.mjs as Railway cron (every 10-15 min)

koala73 added 2 commits March 5, 2026 14:31
- Increase polling intervals (markets 8→12min, feeds 15→20min, crypto 8→12min)
- Increase background tab hiddenMultiplier from 10→30 (polls 3x less when hidden)
- Double CDN s-maxage TTLs across all cache tiers in gateway
- Add CDN-Cache-Control header for Cloudflare-specific longer edge caching
- Add ETag generation + 304 Not Modified support in gateway (zero-byte revalidation)
- Add CDN-Cache-Control to bootstrap endpoint
- Add explicit SPA rewrite rule in vercel.json for CF proxy compatibility
- Add Cache-Control headers for /map-styles/, /data/, /textures/ static paths
- vercel.json: apply no-cache headers to ALL SPA routes (same regex as
  rewrite rule), not just / and /index.html — prevents CF proxy from
  caching stale HTML that references old content-hashed bundle filenames
- Polymarket: add server-side aggregation via Railway seed script that
  fetches all tags once and writes to Redis, eliminating 11-request
  fan-out per user per poll cycle
- Bootstrap: add predictions to hydration keys for zero-cost page load
- RPC handler: read Railway-seeded bootstrap key before falling back to
  live Gamma API fetch
- Client: 3-strategy waterfall (bootstrap → RPC → fan-out fallback)
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Building Building Preview, Comment Mar 5, 2026 0:38am

Request Review

@koala73 koala73 merged commit 320786f into main Mar 5, 2026
2 of 3 checks passed
aldoyh pushed a commit to aldoyh/worldmonitor that referenced this pull request Mar 6, 2026
…oala73#1058)

* perf: reduce Vercel data transfer costs with CDN optimization

- Increase polling intervals (markets 8→12min, feeds 15→20min, crypto 8→12min)
- Increase background tab hiddenMultiplier from 10→30 (polls 3x less when hidden)
- Double CDN s-maxage TTLs across all cache tiers in gateway
- Add CDN-Cache-Control header for Cloudflare-specific longer edge caching
- Add ETag generation + 304 Not Modified support in gateway (zero-byte revalidation)
- Add CDN-Cache-Control to bootstrap endpoint
- Add explicit SPA rewrite rule in vercel.json for CF proxy compatibility
- Add Cache-Control headers for /map-styles/, /data/, /textures/ static paths

* fix: prevent CF from caching SPA HTML + reduce Polymarket bandwidth 95%

- vercel.json: apply no-cache headers to ALL SPA routes (same regex as
  rewrite rule), not just / and /index.html — prevents CF proxy from
  caching stale HTML that references old content-hashed bundle filenames
- Polymarket: add server-side aggregation via Railway seed script that
  fetches all tags once and writes to Redis, eliminating 11-request
  fan-out per user per poll cycle
- Bootstrap: add predictions to hydration keys for zero-cost page load
- RPC handler: read Railway-seeded bootstrap key before falling back to
  live Gamma API fetch
- Client: 3-strategy waterfall (bootstrap → RPC → fan-out fallback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant