Skip to main content

JavaScript Caching Test

What is it?

Browser caching of JavaScript is one of the highest-leverage wins for content-heavy sites where users browse multiple pages per session. Cached scripts skip the network entirely on repeat visits, avoiding the full download and parse cost on every subsequent load while still letting you push fresh code through versioned filenames. This test checks whether the external JavaScript files served with your page include the caching headers that let browsers store and reuse them, and flags any responses that miss out on browser caching.

Why JavaScript caching matters

JavaScript bundles can be the largest single asset on a page beyond images, and they typically change far less often than the HTML or content. That makes them ideal for aggressive caching: a returning visitor with the script already cached avoids the entire download and parse cost on every subsequent page load. On a content-heavy site where users browse multiple pages per session, properly cached JavaScript dramatically improves perceived speed across the entire visit.

Modern best practice pairs long cache lifetimes with versioned filenames: every build emits files like app.7f3c1e.js, where the hash changes whenever the contents change. With this pattern you can set Cache-Control: public, max-age=31536000, immutable safely, because changes ship under new filenames and the cache can never serve stale code. Most modern build tools (Webpack, Vite, Rollup, esbuild) emit hashed filenames automatically.

Common caching gaps

  • No Cache-Control header, forcing browsers to revalidate every request.
  • Short max-age on versioned files where a year would be appropriate.
  • no-cache or no-store directives on static JavaScript, which belong on dynamic responses instead.
  • Cookies on script requests that prevent shared caching at the CDN.

This test reports the caching headers on your page's JavaScript files and flags responses that miss out on browser caching. The fix guide below covers configuring cache headers on the major web servers and CDNs, the role of build-time versioning, and how to verify caching is working as expected.

Pass rate:

  • Top 100 websites: 96%
  • All websites: 79%
Pass rates of Top 100 US websites
2021

98%

2022

96%

2023

95%

2024

96%

100

75

50

25

0

How do I fix it?

This test fails when external JavaScript files are served without caching headers that allow browsers to store and reuse them. Cached scripts skip the network on repeat visits, reducing load time and bandwidth for returning users. Fixing this issue is a server or CDN configuration change.

Where to make the change

  • Server configuration: add Cache-Control: public, max-age=31536000, immutable to JavaScript responses, paired with versioned filenames.
  • CDN configuration: set a default cache rule for *.js assets at the edge.
  • Build pipeline: emit hashed filenames (for example app.7f3c1e.js) so cache lifetimes can be long without risking stale code.
  • WordPress and plugins: caching and CDN plugins handle JS cache headers automatically.

Common causes and how to resolve them

  • No Cache-Control header: add one. Without it, browsers revalidate on every page load.
  • Short max-age: bump to a year for versioned files. Use a shorter lifetime only for unversioned scripts that may change in place.
  • no-cache or no-store on static JS: remove these directives; they belong on dynamic responses, not static assets.
  • Cookies on script requests: serve scripts from a cookie-free subdomain or a CDN to enable shared caching.

Best practices

  • Versioned filenames: hashed file names plus immutable caching is the gold standard for cache effectiveness.
  • Self-host critical scripts: hosting third-party scripts yourself lets you control cache headers and avoid vendor outages.
  • Audit with DevTools: the Network panel's "Disk cache" column shows whether each script is genuinely served from cache on repeat visits.

Dominate search today on Google and AI Engines.

Join 85,000+ SaaS Marketers, Growth Agencies, Content-Led Companies and E-commerce Brands.

See Pricing
Dashboard preview showing SEO site checkup metrics, page group insights, and issue prioritization