Commit: 1729b90eae7140fc77ed2f87007866fba410674c Author: Hannes Magnusson <[email protected]> Thu, 21 Nov 2013 23:22:57 -0800 Parents: 046a258ee670e247f5eecc6dc210c9ea41f61c71 Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=1729b90eae7140fc77ed2f87007866fba410674c Log: Create a quick cached wrapper to attempt to gzip and cache static files We don't really control how the mirrors configure these things, so we have to do it ourselves.. Changed paths: A cached.php M include/footer.inc M include/header.inc Diff: diff --git a/cached.php b/cached.php new file mode 100644 index 0000000..196fd77 --- /dev/null +++ b/cached.php @@ -0,0 +1,40 @@ +<?php +$_SERVER['BASE_PAGE'] = 'cached.php'; +include_once 'include/prepend.inc'; + +if (!isset($_GET["t"], $_GET["f"])) { + header("Location: http://php.net/"); + exit; +} + +$tsstring = gmdate("D, d M Y H:i:s ", $_GET["t"]) . "GMT"; +if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && + ($_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring)) { + header("HTTP/1.1 304 Not Modified"); + exit; +} + +header("Last-Modified: " . $tsstring); + +$abs = $_SERVER["DOCUMENT_ROOT"]. "/" .(string)$_GET["f"]; +$abs = realpath($abs); + +if (strncmp($abs, $_SERVER["DOCUMENT_ROOT"], strlen($_SERVER["DOCUMENT_ROOT"])) != 0) { + header("Location: http://php.net"); + exit; +} +if (substr($abs, -3) == ".js" || substr($abs, -5) == ".json") { + header("Content-Type: application/javascript"); +} elseif (substr($abs, -4) == ".css") { + header("Content-Type: text/css"); +} + +if (function_exists("ob_gzhandler")) { + ob_start("ob_gzhandler"); + readfile($abs); + ob_end_flush(); +} else { + readfile($abs); +} + + diff --git a/include/footer.inc b/include/footer.inc index 49640da..b8a2db2 100644 --- a/include/footer.inc +++ b/include/footer.inc @@ -62,15 +62,15 @@ <!-- External and third party libraries. --> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> - <script type="text/javascript" src="/js/ext/hogan-2.0.0.min.js"></script> - <script type="text/javascript" src="/js/ext/typeahead.min.js"></script> + <script type="text/javascript" src="/cached.php?f=/js/ext/hogan-2.0.0.min.js&t=2"></script> + <script type="text/javascript" src="/cached.php?f=/js/ext/typeahead.min.js&t=2"></script> <?php // Nick bjori's last modified code for our own JS files. $jsfiles = array('search.js', 'common.js'); foreach ($jsfiles as $filename) { $path = dirname(dirname(__FILE__)).'/js/'.$filename; - echo '<script type="text/javascript" src="/js/'.$filename.'?t='.@filemtime($path).'"></script>'; + echo '<script type="text/javascript" src="/cached.php?f=/js/'.$filename.'&t='.@filemtime($path).'"></script>'; } include 'uservoice.inc'; diff --git a/include/header.inc b/include/header.inc index 1167845..e4b347c 100755 --- a/include/header.inc +++ b/include/header.inc @@ -50,7 +50,7 @@ if (isset($shortname) && $shortname) { <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,400italic,600italic|Source+Code+Pro&subset=latin,latin-ext' rel='stylesheet' type='text/css'> <?php foreach($CSS as $filename => $modified): ?> -<link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>styles/<?php echo $filename?>?t=<?php echo $modified?>" media="screen"> +<link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>cached.php?f=styles/<?php echo $filename?>&t=<?php echo $modified?>fda" media="screen"> <?php endforeach ?> <!--[if lte IE 7]> -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
