1

I have a javascript file which is frequently updated on the server (every hour). It is a plugin used in websites by the website's users. It is served millions time a day.

In order for users to get the latest copy I use a header with:

cache-control: public,max-age=1800,stale-while-revalidate=3600, immutable

(Safari doesn't support stale-while-revalidate so it is ignored).

When changing the file, all browsers catch up within one hour except than Safari, where small percent of users continue to use old version of the file (could be weeks old). Seems it is caused by returning users (users which got into a website, than got back a week later).

Is there any reason why Safari is using an old version of the file though the max-age is set?

Dani Magen
  • 329
  • 3
  • 12

1 Answers1

0

Do not use immutable for files that change. Only use that for versioned assets that can be stored indefinitely.

Individual browser implementations get to decide independently how long they keep stale assets. immutable assets might appear to receive updates only because the browser decides to removes a stale cached file.

from... https://simonhearne.com/2022/caching-header-best-practices/#2-immutable

Immutable # These assets that can be stored by the browser indefinitely because they never change. Use this for versioned assets (e.g. main.v123.min.css or main.min.css?v=123).

Carter Medlin
  • 11,857
  • 5
  • 62
  • 68