-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcacheBuster.vtl
41 lines (41 loc) · 2.02 KB
/
cacheBuster.vtl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!-- I: cache-buster-dev -->
## CACHE BUSTER
#set( $enqueuedFiles = [] )##
#macro( cacheBuster $filePath $fileType $fileAttr )##
## CHECK TO MAKE SURE $filePath IS SET AND NOT ALREADY INCLUDED ON THE PAGE SOMEWHERE...
#if( $UtilMethods.isSet($filePath) && $enqueuedFiles.indexOf($filePath) < 0 )##
## ADD FILE TO ENQUEUEDFILES ARRAY
#set( $_dummy = $enqueuedFiles.add($filePath) )##
## PROCESS FILE AND PRINT ON PAGE
## get file name
#set( $_file = $filePath.substring( $math.add($filePath.lastIndexOf('/'),1) ) )##
#set( $conhost = " +conhost:$!{host.identifier}" )##
## query dotCMS for file
#set( $_cbFile = $dotcontent.pull("+structureName:FileAsset +FileAsset.fileName:${_file}$!{conhost} +languageId:1", 1, 'modDate desc') )##
## IF FILE IS FOUND GET/SET MODEDATE
#if( $_cbFile.size() > 0 )##
#set( $_cbFile = $_cbFile.get(0) )##
#set( $_cbModDate = $date.format("yyyymmddHms", $_cbFile.modDate) )##
#end##
## MODDATE FOUND, ADD CACHEBUSTER!
#if( $UtilMethods.isSet($_cbModDate) )##
#if( $fileType == 'link' || $fileType == 'stylesheet' || $fileType == 'css' )##
<link type="text/css" rel="stylesheet" href="${filePath}?$!{_cbModDate}"#if( $UtilMethods.isSet($fileAttr) ) media="${fileAttr}"#end />
#elseif( $fileType == 'script' || $fileType == 'javascript' || $fileType == 'js' )##
<script#if( $UtilMethods.isSet($fileAttr) ) ${fileAttr}#end type="text/javascript" src="${filePath}?$!{_cbModDate}"></script>
#end##
## NO MOD DATE :-(
#else##
## RENDER HTML
#if( $fileType == 'link' || $fileType == 'stylesheet' || $fileType == 'css' )##
<link type="text/css" rel="stylesheet" href="${filePath}"#if( $UtilMethods.isSet($fileAttr) ) media="${fileAttr}"#end>
#elseif( $fileType == 'script' || $fileType == 'javascript' || $fileType == 'js' )##
<script#if( $UtilMethods.isSet($fileAttr) ) ${fileAttr}#end type="text/javascript" src="${filePath}"></script>
#end##
#end##
#set ( $_cbModDate = '' )##
#set ( $_file = '' )##
#set ( $_cbFile = '' )##
#set ( $conhost = '' )##
#end## isset $filePath && $filePath is not in $enqueuedFiles array
#end## macro