diff options
author | Arun Persaud <arun@nubati.net> | 2012-06-03 09:24:23 -0700 |
---|---|---|
committer | Arun Persaud <arun@nubati.net> | 2012-06-03 09:24:23 -0700 |
commit | ee441e7cba2a15b7a617f103b511545f4029a174 (patch) | |
tree | 0f99e6c5dccdc8b767a8b0c965164a592c8657ef /index.php | |
parent | 20cba444993baea357308bf746d3675438c548bc (diff) | |
download | photo-tags-ee441e7cba2a15b7a617f103b511545f4029a174.tar.gz photo-tags-ee441e7cba2a15b7a617f103b511545f4029a174.tar.bz2 photo-tags-ee441e7cba2a15b7a617f103b511545f4029a174.zip |
add autoversioning of css and js files
automatically add the md5 hash to the filename and then use .htaccess to filter it out again.
This way we don't need to change the filename and the client can cache correctly
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -25,14 +25,29 @@ else $pic = -1; /* end parse flags */ +/* autoversioning of js and css files */ +function autoversion($file) +{ + /* changes the file name of e.g. css/style.css to css/style.<md5>.css/js + * this way the browser can cache the file and will reload it if the file changed + * needs to have .htaccess set up correctly to link back to css/style.css */ + + /* only use it for file that have an absolut path */ + if(!file_exists(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file)) + return $file; + + $md5 = md5_file(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file); + return preg_replace('{\\.([^./]+)$}', ".$md5.\$1", $file); +} + /* The basic layout */ ?> <html> <title><?php echo htmlspecialchars($title) ?></title> -<script src = "<?php echo $webbase?>/js/d3.min.js"></script> -<link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/css/normalize.css" /> -<link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/css/style.css" /> +<script src = "<?php echo $webbase.autoversion("/js/d3.min.js")?>"></script> +<link rel="stylesheet" type="text/css" href="<?php echo $webbase.autoversion("/css/normalize.css")?>" /> +<link rel="stylesheet" type="text/css" href="<?php echo $webbase.autoversion("/css/style.css")?>" /> <body> @@ -68,7 +83,7 @@ page <span class="index"></span> </footer> -<script src = "<?php echo $webbase?>/js/photo-tags.js"></script> +<script src = "<?php echo $webbase.autoversion("/js/photo-tags.js")?>"></script> <script type="text/javascript" > /*hand parameters over to javascript*/ var page=<?php echo $page ?>; |