From 9d189605d5ccdbd7125f2e8839c63fa2028d44c1 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Tue, 8 May 2012 20:42:59 -0700 Subject: [PATCH] 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. --- .gitignore | 1 + INSTALL | 6 +++++- htaccess.template | 10 ++++++++++ include/output.php | 29 ++++++++++++++++++++++------- 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 htaccess.template diff --git a/.gitignore b/.gitignore index 6a0fae2..73d57b1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pics/arrow2.svg pics/arrow3.svg scoretest.txt testscoring.php +.htaccess \ No newline at end of file diff --git a/INSTALL b/INSTALL index 1929213..886a94d 100644 --- a/INSTALL +++ b/INSTALL @@ -55,6 +55,10 @@ Installation return; } -3) Log in and enjoy ;) +3) install .htaccess: copy htaccess.template to .htaccess and edit it to set RewriteBase. + If your site is at http://example.org/~test/edoko you need to set + RewriteBase to /~test/edoko + +4) Log in and enjoy ;) Arun diff --git a/htaccess.template b/htaccess.template new file mode 100644 index 0000000..351842c --- /dev/null +++ b/htaccess.template @@ -0,0 +1,10 @@ +RewriteEngine on + +# need to set this to your web path +RewriteBase / + +# hide git directory (and others) +RedirectMatch 404 \.(git|cvs|svn|bzr|hg)(/.*|$) + +# use autoversioning of js and css files +RewriteRule ^(.*)\.[[:xdigit:]]{32}\.(css|js)$ $1.$2 [L] 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() - - - - - - - + " /> + " /> + "/> + + + + -- 2.17.1