diff options
-rw-r--r-- | itjs.class | 20 | ||||
-rw-r--r-- | itjs.php | 19 |
2 files changed, 22 insertions, 17 deletions
@@ -217,6 +217,26 @@ function crcurl($url) return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn)))); } +static function far_future_headers() +{ + $crc = $_REQUEST['c'] ?: $_REQUEST['s']; + if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) + { + header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has + exit; + } + + if ($crc != "-") + @header("Etag: alwaysvalid"); # we have checksums in the url. client should always keep the version he downloaded along with the html + + if (it::is_live() && !$_REQUEST['retry']) + { + $keeptime = $crc == "-" ? 0 : ($crc ? 30*86400 : 900); # long expire if checksum present + header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers + header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT"); + } +} + } ?> @@ -24,16 +24,11 @@ require "itools/itools.lib"; if (EDC('slow' . it::match('\.(css|js)\b', U($_GET)))) sleep(5); -$crc = $_REQUEST['c'] ?: $_REQUEST['s']; -if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) -{ - header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has - exit; -} - if (it::match('/server/', $_SERVER['DOCUMENT_ROOT'])) exit; # useless here. cannot write tempfiles +itjs::far_future_headers(); # may exit + $files = itjs::filenames($_GET['files'] ?: it::match('/itjs/([-a-z0-9_,.]*)', $_SERVER['PHP_SELF'])); $data = itjs::filecontents($files); $file = end($files); @@ -82,16 +77,6 @@ else if (!it::match('\.html$', $file)) header("Content-Type: application/x-javascript; charset=$charset"); } -if ($crc != "-") - @header("Etag: alwaysvalid"); # we have checksums in the url. client should always keep the version he downloaded along with the html - -if (it::is_live() && !$_REQUEST['retry']) -{ - $keeptime = $crc == "-" ? 0 : ($crc ? 30*86400 : 900); # long expire if checksum present - header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers - header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT"); -} - $data = itjs::strip($data); if ($_REQUEST['boot']) |