0
votes

multiple JS files (hosted by me) are embedded in various website's code as script tags to which I don't have access to. So, I couldn't invalidate cache by maintaining a fingerprint in the URL, or through URL parameters.

The files are quite large, so caching is mandatory. What are other ways there to invalidate browser cache apart from modifying the src?

The solution I'm considering now is to maintain a wrapper script which is not cached, that calls the actual scripts. By this way, I could maintain some sort versioning in the wrapper script. This does not seem elegant, are there other ways?

If these don't work out, I'll consider reducing the expires header.

I've done other optimisations like minifying, using a CDN etc.

2

2 Answers

1
votes

Your solution to use a wrapper script is probably the optimum solution.

One mains script in the document DOM that calls your wrapper script to attach the appropriate scripts on load.

You could use something like requirejs to manage this which also has some cache busting built in according to this: Prevent RequireJS from Caching Required Scripts

0
votes

that calls the actual scripts

Why not just return a 302 response from the entry point URL?

(a 302 response can itself be cached - in your scenario this should be for a short period)