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 /lib/exe/css.php | |
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 'lib/exe/css.php')
-rw-r--r-- | lib/exe/css.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 5d8f7058a..90f0109ef 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -92,7 +92,20 @@ function css_out(){ if(css_cacheok($cache,array_keys($files),$tplinc)){ http_conditionalRequest(filemtime($cache)); if($conf['allowdebug']) header("X-CacheUsed: $cache"); - readfile($cache); + + // finally send output + if (http_accepts_gzip() && http_gzip_valid($cache)) { + header('Vary: Accept-Encoding'); + header('Content-Encoding: gzip'); + if (!http_sendfile($cache.'.gz')) readfile($cache.".gz"); +# } else if (http_accepts_deflate()) { +# header('Vary: Accept-Encoding'); +# header('Content-Encoding: deflate'); +# readfile($cache.".zip"); + } else { + if (!http_sendfile($cache)) readfile($cache); + } + return; } else { http_conditionalRequest(time()); @@ -124,9 +137,20 @@ function css_out(){ // save cache file io_saveFile($cache,$css); + copy($cache,"compress.zlib://$cache.gz"); // finally send output - print $css; + if (http_accepts_gzip()) { + header('Vary: Accept-Encoding'); + header('Content-Encoding: gzip'); + print gzencode($css,9,FORCE_GZIP); +# } else if (http_accepts_deflate()) { +# header('Vary: Accept-Encoding'); +# header('Content-Encoding: deflate'); +# print gzencode($css,9,FORCE_DEFLATE); + } else { + print $css; + } } /** |