implement crude cache busting code for .js and .css files

This commit is contained in:
Isaac Connor 2017-11-01 09:41:19 -04:00
parent 3deb8a35bb
commit e6918cd1bd
2 changed files with 18 additions and 6 deletions

View File

@ -2060,6 +2060,18 @@ function detaintPath( $path ) {
return( $path );
}
function cache_bust( $file ) {
# Use the last modified timestamp to create a link that gets a different filename
# To defeat caching. Should probably use md5 hash
$cacheFile = '/cache/'.basename($file).'-'.filemtime($file);
if ( file_exists( ZM_PATH_WEB.$cacheFile ) or symlink( ZM_PATH_WEB.'/'.$file, ZM_PATH_WEB.$cacheFile ) ) {
return $cacheFile;
} else {
Warning("Failed linking $file to $cacheFile");
}
return $file;
}
function getSkinFile( $file ) {
global $skinBase;
$skinFile = false;
@ -2068,7 +2080,7 @@ function getSkinFile( $file ) {
if ( file_exists( $tempSkinFile ) )
$skinFile = $tempSkinFile;
}
return( $skinFile );
return $skinFile;
}
function getSkinIncludes( $file, $includeBase=false, $asOverride=false ) {

View File

@ -60,11 +60,11 @@ if ( file_exists( "skins/$skin/css/$css/graphics/favicon.ico" ) ) {
<link rel="stylesheet" href="css/reset.css" type="text/css"/>
<link rel="stylesheet" href="css/overlay.css" type="text/css"/>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"/>
<link rel="stylesheet" href="<?php echo $skinCssFile ?>" type="text/css" media="screen"/>
<link rel="stylesheet" href="<?php echo cache_bust($skinCssFile) ?>" type="text/css" media="screen"/>
<?php
if ( $viewCssFile ) {
?>
<link rel="stylesheet" href="<?php echo $viewCssFile ?>" type="text/css" media="screen"/>
<link rel="stylesheet" href="<?php echo cache_bust($viewCssFile) ?>" type="text/css" media="screen"/>
<?php
}
if ( $viewCssPhpFile ) {
@ -138,18 +138,18 @@ if ( file_exists( "skins/$skin/css/$css/graphics/favicon.ico" ) ) {
}
if ( $cssJsFile ) {
?>
<script type="text/javascript" src="<?php echo $cssJsFile ?>"></script>
<script type="text/javascript" src="<?php echo cache_bust($cssJsFile) ?>"></script>
<?php
} else {
?>
<script type="text/javascript" src="skins/classic/js/classic.js"></script>
<?php } ?>
<script type="text/javascript" src="<?php echo $skinJsFile ?>"></script>
<script type="text/javascript" src="<?php echo cache_bust($skinJsFile) ?>"></script>
<script type="text/javascript" src="js/logger.js"></script>
<?php
if ( $viewJsFile ) {
?>
<script type="text/javascript" src="<?php echo $viewJsFile ?>"></script>
<script type="text/javascript" src="<?php echo cache_bust($viewJsFile) ?>"></script>
<?php
}
?>