Member-only story
HTML5 escape .js & .css cache hell.
1 min readJan 2, 2020
Every developers hell. Browser caching of .js and .css files.
There are far too many ‘solutions’ on stackexchange with incomplete solutions. I found this provided a balance for me to control users refresh rates remotely and manage server load.
By dynamically creating the url for javascript and style files we can force browsers to update or cache files.
<script type="text/javascript" language="javascript">
console.log("(new Date()).getDate()=", (new Date()).getDate())
var versionUpdate = (new Date()).getTime();
console.log("versionUpdate=", versionUpdate)
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "/static/load_runsheet.js?v=" + versionUpdate;
document.body.appendChild(script);
//
var styles = document.createElement('link');
styles.rel = 'stylesheet';
styles.type = 'text/css';
styles.media = 'screen';
styles.href = '/static/style.css?v=' + versionUpdate;
//
document.getElementsByTagName('head')[0].appendChild(styles);
</script>
YMMV. Let me know what works for you.