@shawncrawley and I had a good discussion about the trouble of browser caching scripts and how to get around users needing to do hard refreshes when you make updates to your scripts. There are a few solutions out there that you can find on stack overflow like these:
The problem with the first solution is that some browsers don't cache resources with query strings in them ever (e.g. myfile.js?version=11), which means you would take a performance hit. The problem with renaming your file all the time is it becomes difficult to track history of the file in your versioning software. On a somewhat related note, it is also a best practice to minify and munge (m&m) js and css files to decrease the size of the files and increase the speed of page loads. @erice has made a bash script that we use at Aquaveo that m&ms some of our scripts using a Google tool. With that insufficient background, I have the following proposals:
(1) We create a new tethys cli tool that will automatically m&m all js and css files for an app and in the process name the m&m'ed files with a timestamp (e.g. myfile20160215.min.js) and clear out older m&m'ed files. For bonus points, this command line tool would only m&m files that have changed.
(2) We create a new template tag as an alternative for the static tag that would:
(a) load the original source file when debug = True (e.g. myfile.js) and load the m&m'ed version of the file when debug = False (e.g. myfileXXXXXX.min.js) if it exists. This gives you the ability to debug your scripts when you are developing and maximizes resource load speeds and obfuscation for production use.
(b) smartly detect the time stamped portion of the m&m'ed file and replace accordingly upon template render to prevent needing to manually change the reference in all the templates that use the files every time they are updated.
The workflow would be that the developer runs the m&m when a css or js file changes and new m&m files are generated for the ones that changed. The developer uses the custom static tag to load all static files using the name of the source file as they do now. With this approach, your original source file keeps the same name always, and can be appropriately tracked in your version control. Only the m&m'ed versions of the scripts have their names changed frequently, which doesn't matter much because they are unreadable.
Thoughts?