Skip to content

Instantly share code, notes, and snippets.

Created Nov 19, 2019
What would you like to do?
Custom tag for ColdFusion implementing cache busting
Goal: implement timestamp-based cache busting
For example: instead of loading a javascript file from "", it'll load it from ""
Usage examples:
- add as global tag and: <CF_js_script src="/js/myscript.js">
- <cfimport prefix="akaita" taglib="customTags"> and then <akaita:js_script src="/js/myscript.js"></akaita:js_script>
<CFIF thisTag.executionMode IS "start">
<CFSET scriptFile = expandPath(attributes.src)>
<CFIF fileExists(scriptFile)>
<CFSET fileInfo = getFileInfo(scriptFile)>
<CFSET timeStamp = dateFormat(fileInfo.lastModified, "yyyymmdd")
& timeFormat(fileInfo.lastModified, "HHmmss")>
<CFOUTPUT>File #attributes.src# not found</CFOUTPUT>
<SCRIPT type="text/javascript" src="#attributes.src#?ver=#timestamp#"></SCRIPT>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment