There's many Q&A's about how to prevent users' browsers from caching old versions of JS and CSS files.
For frequent users of a web app, I want those files to be cached, but when I update the JS / CSS content, then I want the user to automatically fetch the new version.
No doubt others have also used something similar, but I didn't like most of the suggestions I found, and I came up with this:
<?php $css_last_mod = filemtime("path_to/styles.css"); ?>
<link href="path_to/styles.css?v=<?php echo $css_last_mod; ?>" rel="stylesheet" />
Include this in your header, and the CSS file's last modified timestamp will only change when the file is updated. (and thus indicate to the browser that there's a new version)
<link href="includes_public/styles.css?v=1579628430" rel="stylesheet">
And of course the same concept can be used for JS files.
Are there any known compatibility issues with this?
webpack