From ca2b464bb4f7cab9b83cd6e2508c6079e3f948cc Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 18 Jan 2009 19:43:54 +0100 Subject: Add capability to send pre-compressed js & css files if the browser can accept them - save a gzipped version of js & css files at the same time as the uncompressed version is cache - basic content negotiation to send the compressed files - uses sendfile (for compressed or uncompressed versions) if config indicates its available darcs-hash:20090118184354-f07c6-66c5b465ab147d83de409708bab2c47d1dafcf8d.gz --- inc/pageutils.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index 1fdb4f2d0..5fea66942 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -578,6 +578,9 @@ function http_conditionalRequest($timestamp){ exit; } +/** + * common routines for handling communication with the client (browser) + */ function http_sendfile($file) { global $conf; @@ -596,4 +599,23 @@ function http_sendfile($file) { return false; } +function http_accepts_gzip() { + return !empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false); +} + +function http_accepts_deflate() { + return !empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'deflate') !== false); +} +/** + * return true if there exists a gzip version of the uncompressed file (samepath/samefilename.sameext.gz) + * created after the uncompressed file + */ +function http_gzip_valid($uncompressed_file) { + $gzip = $uncompressed_file.'.gz'; + if (filemtime($gzip) < filemtime($uncompressed_file)) { // filemtime returns false (0) if file doesn't exist + return copy($uncompressed_file, 'compress.zlib://'.$gzip); + } + + return true; +} //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3