Dynamic File Cachebuster Variables


There are times where you might want to add a dynamic variable to the end of a file to help browsers repull the file after changes have been made to it. This can be common with things like CSS and JS, which might change frequently, but can get caught in the browser cache. You can use the following example to created auto-updating cachebuster variables on asset links. When the file is modified, the timestamp will change, and the browser should re-request the file automatically.


#set($cachebuster = $webapi.getLiveFileAsset($webapi.getIdentifierByURI('/common/css/facebox.css')).getModDate().getTime())
<link rel="stylesheet" type="text/css" href="/css/styles.css?${cachebuster}" />