From 7e9f1b63e509263d2143b311862ebcd261226b93 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 29 Apr 2012 18:59:08 +0200 Subject: [PATCH] MDL-26028 use X-Sendfile for theme images and javascript --- theme/image.php | 7 +++++++ theme/javascript.php | 8 ++++++++ theme/yui_image.php | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/theme/image.php b/theme/image.php index 63acfaf0053..c8dd7acc643 100644 --- a/theme/image.php +++ b/theme/image.php @@ -138,6 +138,9 @@ if ($rev > -1) { // parameters to get the best performance. function send_cached_image($imagepath, $rev) { + global $CFG; + require("$CFG->dirroot/lib/xsendfilelib.php"); + $lifetime = 60*60*24*30; // 30 days $pathinfo = pathinfo($imagepath); $imagename = $pathinfo['filename'].'.'.$pathinfo['extension']; @@ -154,6 +157,10 @@ function send_cached_image($imagepath, $rev) { header('Content-Type: '.$mimetype); header('Content-Length: '.filesize($imagepath)); + if (xsendfile($imagepath)) { + die; + } + // no need to gzip already compressed images ;-) readfile($imagepath); diff --git a/theme/javascript.php b/theme/javascript.php index 6f7ebadc8be..4151172a711 100644 --- a/theme/javascript.php +++ b/theme/javascript.php @@ -99,6 +99,9 @@ if ($rev > -1) { // parameters to get the best performance. function send_cached_js($jspath) { + global $CFG; + require("$CFG->dirroot/lib/xsendfilelib.php"); + $lifetime = 60*60*24*30; // 30 days header('Content-Disposition: inline; filename="javascript.php"'); @@ -108,6 +111,11 @@ function send_cached_js($jspath) { header('Cache-Control: max-age='.$lifetime); header('Accept-Ranges: none'); header('Content-Type: application/javascript; charset=utf-8'); + + if (xsendfile($jspath)) { + die; + } + if (!min_enable_zlib_compression()) { header('Content-Length: '.filesize($jspath)); } diff --git a/theme/yui_image.php b/theme/yui_image.php index 23ac987ff29..37dd6ba5075 100644 --- a/theme/yui_image.php +++ b/theme/yui_image.php @@ -66,6 +66,9 @@ yui_image_cached($imagepath); function yui_image_cached($imagepath) { + global $CFG; + require("$CFG->dirroot/lib/xsendfilelib.php"); + $lifetime = 60*60*24*300; // 300 days === forever $pathinfo = pathinfo($imagepath); $imagename = $pathinfo['filename'].'.'.$pathinfo['extension']; @@ -88,6 +91,10 @@ function yui_image_cached($imagepath) { header('Content-Type: '.$mimetype); header('Content-Length: '.filesize($imagepath)); + if (xsendfile($imagepath)) { + die; + } + // no need to gzip already compressed images ;-) readfile($imagepath);