Guides · Performance

Browser caching and web compression

A fast page should not download the same files again on every visit. Caching and compression reduce transferred data without changing the visible content.

Practical guidePerformance

Cache stable resources

Versioned CSS, JavaScript, fonts and images can often receive long cache durations when their URL changes whenever the file changes.

  • Use reliable file names or version parameters.
  • Give immutable assets long cache lifetimes.
  • Use more cautious rules for HTML that changes frequently.

Compress text content

HTML, CSS, JavaScript, JSON and SVG compress efficiently. The server can use Gzip or Brotli depending on server and client capabilities.

  • Enable compression at server level rather than application code.
  • Do not repeatedly compress formats such as JPEG that are already compressed.
  • Check Content-Encoding in the HTTP response.

Avoid stale cache problems

A long cache lifetime without versioning can leave visitors with an old stylesheet after deployment. Caching must therefore be designed together with the release process.

  • Change asset versions when important files change.
  • Test a deployment with a browser that has already visited the site.
  • Document cache rules in server configuration.

Practical checklist

  • Static assets have an appropriate cache policy.
  • HTML uses a more cautious cache policy.
  • Compression is active for text formats.
  • Asset versions change when files change.
  • Headers are verified in production.

Conclusion

Caching and compression are straightforward server-side improvements that benefit almost every page. Their effectiveness depends on a policy that matches the deployment process.