In Sphinx's conf.py I have:
html_css_files = ['css/custom.css']
html_js_files = ['js/custom.js']
However if I make any change in custom.js or custom.css then this change does not reflect to in the user's browser unless http://www.example.com/_static/js/custom.js is forcefully reloaded on the client (similarly for CSS).
How can I force the custom CSS + JS to never cache on the user's browser?
Although the config file looks like it only accepts normal string values, it is really just a Python script, so we can import and use functions such as a random number generator.
At the top of
conf.pyadd this line:Change your custom CSS + JS to:
This will make your custom CSS + JS files load like the vanilla CSS + JS files, with a random 8-character slug at the end - thus disabling caching:
Note that if you're running Sphinx in Docker then the
?v=xxxxxxxxslug will not change unless you run yourdocker buildwith the--no-cacheoption.