Skip to content

perf: reduce Vercel data transfer costs with CDN optimization#1057

Merged
koala73 merged 1 commit intomainfrom
worktree-declarative-gliding-bird
Mar 5, 2026
Merged

perf: reduce Vercel data transfer costs with CDN optimization#1057
koala73 merged 1 commit intomainfrom
worktree-declarative-gliding-bird

Conversation

@koala73
Copy link
Owner

@koala73 koala73 commented Mar 5, 2026

Summary

Reduces Vercel bandwidth and request costs through polling optimization, aggressive CDN caching, and ETag-based revalidation. Paired with Cloudflare Cache Rules configured on the dashboard.

Changes

  • Polling intervals: markets 8→12min, feeds 15→20min, crypto 8→12min, predictions/AIS 10→15min
  • Background tab throttling: hiddenMultiplier 10→30 (hidden tabs poll 3x less)
  • CDN cache TTLs doubled: fast 2→5min, medium 5→10min, slow 15→30min, static 1→2hr
  • CDN-Cache-Control header: Cloudflare-specific longer TTLs (2x s-maxage) for aggressive edge caching with ETag revalidation
  • ETag + 304 Not Modified: Gateway computes FNV-1a hash of response body, returns 304 on unchanged data — zero-byte revalidation
  • Bootstrap CDN-Cache-Control: Separate Cloudflare TTLs for fast/slow bootstrap tiers
  • Explicit SPA rewrite: vercel.json now has a catch-all rewrite to index.html for CF proxy compatibility
  • Static path cache headers: Added immutable Cache-Control for /map-styles/, /data/, /textures/

Cloudflare Cache Rules (configured separately)

  1. Bypass: /sw.js, /, /index.html
  2. Static 1 month: /assets/, /map-styles/, /data/, /textures/
  3. Favicon 7 days: /favico/
  4. API: respect cache-control + strong ETags
  5. Proxy: respect cache-control

Estimated impact

~$900/month reduction (70%) when combined with CF proxy on main domain

Test plan

  • Verify site loads correctly after deploy (no 404 on bundles)
  • Check CF dashboard analytics for cache HIT ratio after 24h
  • Verify API responses include ETag header: curl -I https://api.worldmonitor.app/api/market/v1/list-market-quotes?symbols=AAPL
  • Verify 304 on repeat request: curl -H 'If-None-Match: "<etag>"' -I https://api.worldmonitor.app/api/market/v1/list-market-quotes?symbols=AAPL
  • Confirm CDN-Cache-Control header present on API responses
  • Monitor Vercel usage dashboard for reduced data transfer over next billing cycle

- 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
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 Ready Ready Preview, Comment Mar 5, 2026 10:33am

Request Review

@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.

@koala73 koala73 merged commit 278c69b into main Mar 5, 2026
3 checks passed
aldoyh pushed a commit to aldoyh/worldmonitor that referenced this pull request Mar 6, 2026
…3#1057)

- 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
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