Caching headers for prefetched assets

You can modify headers for any file that isn’t asset-optimized (since those have the special handling, but also potentially create CORS problems since they are served from a different domain). You do this using our custom headers functionality:

For those two, you might use this in your separate headers file, or your toml file though that configuration being more verbose I don’t include it here:

/path/to/therapist.js:
   cache-control: public, max-age=31556926
/path/to/session.js
   cache-control: public, max-age=31556926

If the files have a hash in their names, you might be able to do something like put them all in a single directory, and use this syntax instead to cover all names past and present:

/path/to/*.js:
     cache-control: public, max-age=31556926

Note that both messing with these headers and cachebusting are generally regarded as antipatterns on Netlify - you should let our default caching do the work and NOT cachebust anything, since it slows your site down in many situations. This article has more details if you are curious:

We won’t stop you from doing it your way, so you’re welcome to keep using it, but it creates other problems like this one:

1 Like