From 9d189605d5ccdbd7125f2e8839c63fa2028d44c1 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Tue, 8 May 2012 20:42:59 -0700 Subject: auto-versioning for js and css files. Needs .htaccess to be installed The md5 of the file will be added to the filename of the .js or .css file. .htaccess will remove these again, but the browser will be able to cache correctly now. --- include/output.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/output.php b/include/output.php index 92c301f..a075fb3 100644 --- a/include/output.php +++ b/include/output.php @@ -26,6 +26,21 @@ if(!isset($HOST)) /* functions which only ouput html */ +function autoversion($file) +{ + /* changes the file name of e.g. css/style.css to css/style..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); +} + + function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid) { global $RULES; @@ -410,13 +425,13 @@ function output_header() - - - - - - - + " /> + " /> + "/> + + + + -- cgit v1.2.3-18-g5258