summaryrefslogtreecommitdiffstats
path: root/include/output.php
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2012-05-08 20:42:59 -0700
committerArun Persaud <arun@nubati.net>2012-05-08 20:42:59 -0700
commit9d189605d5ccdbd7125f2e8839c63fa2028d44c1 (patch)
treedf3343a0a368cc12a71da8b7cda8295bbf2bd611 /include/output.php
parent2fb259fc72129bcb9d209368a97c99638ef77001 (diff)
downloade-DoKo-9d189605d5ccdbd7125f2e8839c63fa2028d44c1.tar.gz
e-DoKo-9d189605d5ccdbd7125f2e8839c63fa2028d44c1.tar.bz2
e-DoKo-9d189605d5ccdbd7125f2e8839c63fa2028d44c1.zip
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.
Diffstat (limited to 'include/output.php')
-rw-r--r--include/output.php29
1 files changed, 22 insertions, 7 deletions
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.<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);
+}
+
+
function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
{
global $RULES;
@@ -410,13 +425,13 @@ function output_header()
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<link rel="shortcut icon" href="pics/edoko-favicon.png" />
- <link rel="stylesheet" href="css/normalize.css?v=1" />
- <link rel="stylesheet" href="css/standard.css?v=41" />
- <link rel="stylesheet" href="css/dateinput.css?v=1"/>
- <script type="text/javascript" src="include/jquery.js"> </script>
- <script type="text/javascript" src="include/jquery.tablesorter.js"></script>
- <script type="text/javascript" src="include/jquery.tools.min.js"></script>
- <script type="text/javascript" src="include/game.js"> </script>
+ <link rel="stylesheet" href="<?php echo autoversion("css/normalize.css"); ?>" />
+ <link rel="stylesheet" href="<?php echo autoversion("css/standard.css"); ?>" />
+ <link rel="stylesheet" href="<?php echo autoversion("css/dateinput.css"); ?>"/>
+ <script type="text/javascript" src="<?php echo autoversion("include/jquery.js"); ?>"> </script>
+ <script type="text/javascript" src="<?php echo autoversion("include/jquery.tablesorter.js"); ?>"></script>
+ <script type="text/javascript" src="<?php echo autoversion("include/jquery.tools.min.js"); ?>"></script>
+ <script type="text/javascript" src="<?php echo autoversion("include/game.js"); ?>"> </script>
<script type="text/javascript">
</script>
</head>