diff options
author | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 19:43:54 +0100 |
---|---|---|
committer | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 19:43:54 +0100 |
commit | ca2b464bb4f7cab9b83cd6e2508c6079e3f948cc (patch) | |
tree | 07397aa7b1e16076d45746dad8ab38d405d23e91 /inc | |
parent | 6106ad89147dec3e180931e3cee6c3973aac8150 (diff) | |
download | rpg-ca2b464bb4f7cab9b83cd6e2508c6079e3f948cc.tar.gz rpg-ca2b464bb4f7cab9b83cd6e2508c6079e3f948cc.tar.bz2 |
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
Diffstat (limited to 'inc')
-rw-r--r-- | inc/pageutils.php | 22 |
1 files changed, 22 insertions, 0 deletions
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 : |