No more Shit+F5

Member-only story

Cache busting in Adobe ColdFusion

Akaita
2 min readNov 19, 2019

--

If you find yourself with a web page which doesn’t seem to reflect the changes you make in your javascript or css code, you might just be dealing with a bad caching strategy.

Try to use Shift+F5(Windows) or ⌘ Command + ⌥ Option + E (MacOS). If you can now see the changes you made, you probably have a caching issue.

One way to solve this issue is Cache Busting. Essentially, you can add a query string to the URL of your file torepresent the version of the file. Therefore, every time you update the version of the file, you use a new URL.

For example, instead of querying js/script.js you could query js/script.js?ver=4 .

Now, it’d be brilliant if the server was smart enough to automatically change the value of that query string, right?

In ColdFusion’s specific case, we can create a custom tag in customTags/js_script.cfm such as:

This will make sure that your javascript scripts implement date-based cache busting by appending the ver=#last-modified-date# query parameter. Your javascript will be loaded using a URL similar to https://www.akaita.com/js/myscript.js?ver=20191119160030

Now, there’s multiple ways to use this new custom tag. Please check the official documentation to choose the option that suits your needs. In my case, I opt for using cfimport because of the limitations of my current CI and serverside systems:

Things to keep in mind

  • Afaik, no IDE supports custom tags properly as of today. They’ll keep warning you about them
  • These will make the server automatically handle the cache busting query string, but it will do so by calculating them at runtime… the impact on performance for your server should be negligible, but you should keep an eye on that. Afaik, we have no other option with ColdFusion
  • The web server should be able to implement this cache busting and keep a proper cache or handle ETAGs properly, but I myself didn’t find a way to make IIS do it properly… Please hit me if you can, because I could just be dealing with an obcurely badly configured server (it’s over 10 years old… you can imagine XD)

--

--

Akaita
Akaita

No responses yet

Write a response