We often add a version URL parameter (usually just...
# cfml-general
d
We often add a version URL parameter (usually just v), to stylesheet URLs, and update it when the stylesheet itself changes. It bugs me that when the stylesheet changes, we need to need to update that version number in any calling files. (No we're not using any sort of integrated build process to handle that automatically, maybe someday.) I'm considering replacing that manual version number with a cleaned up timestamp of the stylesheet file on disk, which I'd have to read each time. Do you think not having to maintain that version number manually is worth the ongoing overhead of that getFileInfo() call?
w
fwiw, we set an application var during app init, application.cachebuster and simply append to js and css references as needed. so the cacheability is tied to the application lifespan
☝️ 2
☝🏻 1
s
What we do at work is to generate a
build.cfm
file during deployment that contains the timestamp of the build itself. It contains
<cfset buildStamp = "<yyyy-mm-dd_hh-mm-ss>">
essentially, and then we use
?s=#buildStamp#
on URLs. That forces a (client) refresh and CDN update for each "build" which ensures a consistent fetch of all related files (CSS, JS, etc).
Kevin's approach is a good one too. Both force a few more fetches of your CSS etc if it hasn't changed, but it errs on the side of "safety" in terms of keeping everything updated and in sync.
✔️ 1
w
application.cachebuster = getTickCount();
essentially
j
FWIW, Webpack’s postcss processor will also do this for you automatically, along with minification and optimization for production. It then generates a manifest file that can be read in to provide the
href
location. Then, on every production deploy, a file with a unique hash is generated, and your HTML source serves that specific hashed file. Even if you don’t use Coldbox, the
coldbox-elixir
NPM module can do all of this for you automatically. You can just grab this method and its helpers and put it in your code to handle the manifest file. I can point you to several working examples of this if you are interested
s
Yeah, our frontend team use Webpack and PostCSS for all of that. We use the build stamp approach for the server-side rendered apps (two small public apps, two large internal apps).
d
Thanks folks. We're moving to formal minified builds for some of our code base, but not this piece. But thanks for effectively talking me out of reading the file timestamp all the time, can deal with it locally in other ways.
👍🏻 1
👍 2