From f88b4e9f818ff4dabfe308a3916e3e5acbba69c1 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 25 Nov 2019 09:55:09 +0800 Subject: [PATCH] MDL-67348 theme: Return CSS from localcache if available --- theme/styles.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/theme/styles.php b/theme/styles.php index 1f363231f92..2b25d142401 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -84,6 +84,15 @@ $candidatedir = "$CFG->localcachedir/theme/$rev/$themename/css"; $candidatesheet = "{$candidatedir}/" . theme_styles_get_filename($type, $themesubrev, $usesvg); $etag = theme_styles_get_etag($themename, $rev, $type, $themesubrev, $usesvg); +if (file_exists($candidatesheet)) { + if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { + // We do not actually need to verify the etag value because our files + // never change in cache because we increment the rev counter. + css_send_unmodified(filemtime($candidatesheet), $etag); + } + css_send_cached_css($candidatesheet, $etag); +} + // Ok, now we need to start normal moodle script, we need to load all libs and $DB. define('ABORT_AFTER_CONFIG_CANCEL', true);