diff options
author | Malf Furious <m@lfurio.us> | 2018-11-01 23:02:23 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2019-03-23 21:09:12 -0400 |
commit | 14a20dcb0eae75e6096ec966c9fed6dcc1283993 (patch) | |
tree | 9742b80bb11a8bca2cb590f50603acc5d86c2e3c /app | |
parent | 6e11d642995e2b2644464ef0bb21528e5e0c2456 (diff) | |
download | scrott-14a20dcb0eae75e6096ec966c9fed6dcc1283993.tar.gz scrott-14a20dcb0eae75e6096ec966c9fed6dcc1283993.zip |
Instruct client to cache df.php resources
Since content served by df.php is inherently dynamic, the server wisely
instructs clients to not cache any responses. In pratice, for Scrott,
the resources accessible by df.php are usually static, perhaps only
ocasionally appearing or disappearing.
A consequence of this is that clients have to repeatedly download
several images, often on each page load of the app. Low-bandwidth
clients will especially feel this.
This patch _explicitly_ inserts from headers into the response from
df.php which instruct the client to keep a copy of the resource for 24
hours. The idea being that resource requests will be *drastically*
reduced and if someone updates their head image (for example), that
change will take no-more-than 1 day to propagate.
Signed-off-by: Malf Furious <m@lfurio.us>
Diffstat (limited to 'app')
-rw-r--r-- | app/df.php | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -31,7 +31,8 @@ require_once "class/mesg.class.php"; /* * Serve the resource at the given URI in response to the current * request. When finished, this function will exit PHP and terminate - * this script. + * this script. The response instructs the client to cache the + * result for 24 hours. */ function serveResource(string $uri, ?string $filename = NULL) : void { @@ -40,8 +41,14 @@ function serveResource(string $uri, ?string $filename = NULL) : void if (!$f) exit; + $cachelen = 86400; // secs, 24-hours + $cachedate = gmdate("D, d M Y H:i:s", time() + $cachelen); + header("Content-Type: " . mime_content_type($uri)); header("Content-Length: " . filesize($uri)); + header("Expires: " . $cachedate); + header("Cache-Control: max-age=" . $cachelen); + header("Pragma: cache"); if ($filename) header("Content-Disposition: attachment; filename=\"" . $filename . "\""); |