/** * Sets http headers for proper caching with 304-code according to the file's change data. * * @param ojbect $fileObject the fileObject who's change date should be compared against the * browser's cache-timestsamp * * @return bool indicating if file is cached in browser */ private function _setHttpCacheHeaders($fileObject) { # Do not force 304 caching if disabled by config if (static::$_aggressiveCaching !== true) { return false; } # Collect some information about file requested and file in browser's cache $fileModifiedTimestamp = $fileObject->getMTime(); $fileName = $fileObject->getFileName(); $browserModifiedTimestamp = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null; # Makes the browser respond with HTTP_IF_MODIFIED_SINCE and If-None-Match for E-Tag validation header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $fileModifiedTimestamp) . " GMT"); header('ETag: "' . md5($fileModifiedTimestamp . $fileName) . '"'); header('Cache-Control: public'); # Now check if file content needs to be send if ($browserModifiedTimestamp !== null && $fileModifiedTimestamp <= $browserModifiedTimestamp) { http_response_code(304); return true; } return false; }