Prompt
How do I reduce latency for static assets like JS, CSS, and fonts?
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
To reduce latency for static assets like JavaScript, CSS, and fonts, focus on getting them to the user from the nearest possible location, as quickly as possible, and in the smallest possible form.
1. Use a CDN
Serve static files from a Content Delivery Network so they’re cached on edge servers close to users. This usually gives the biggest latency improvement.
2. Enable strong caching
Set long-lived cache headers for static assets, for example:
Cache-Control: public, max-age=31536000, immutablefor versioned files- Use fingerprinted filenames like
app.3f2c1a.jsso you can cache aggressively without worrying about stale files
3. Compress assets
Use:
- Brotli for JS/CSS/fonts when supported
- Gzip as fallback
Compression reduces transfer time, especially on slower networks.
4. Minify and bundle intelligently
- Minify JS/CSS to reduce file size
- Split code so users only download what they need initially
- Avoid shipping large unused libraries
5. Preload critical assets
Use:
<link rel="preload">for fonts and critical CSS/JSfont-display: swapfor fonts to avoid blocking text rendering
6. Optimize font delivery
Fonts are often slower than expected:
- Prefer WOFF2
- Subset fonts to include only needed glyphs
- Self-host fonts if it improves caching/control
- Preload only the fonts actually used above the fold
7. Reduce request overhead
- Serve assets over HTTP/2 or HTTP/3
- Keep connections warm with proper caching and persistent connections
- Reduce the number of separate files when appropriate
8. Put assets on a fast origin
If not using a CDN:
- Use a geographically distributed storage/origin
- Make sure TLS is configured well
- Ensure the server has low TTFB and no extra redirects
9. Cache at multiple layers
- Browser cache
- CDN cache
- Reverse proxy cache
- Application cache (for asset generation pipelines)
10. Audit third-party assets
External JS/CSS/fonts can add latency and unpredictability. Host critical assets yourself when possible.
If you want, I can also give you:
- a best-practice HTTP cache header setup
- a sample Nginx/Apache/CDN configuration
- or a priority checklist for JS/CSS/fonts specifically