From b46855b37bcc823c2d22a62d228df99b36e162ed Mon Sep 17 00:00:00 2001 From: "E.Smith" <31170571+azlm8t@users.noreply.github.com> Date: Sun, 26 Nov 2017 13:39:19 +0000 Subject: [PATCH] http: Increase maxage for caching for images. (#4594). Images were previously cached for 10 seconds. Since images rarely change and we now use icons for categories in the epg grid, it makes sense to cache them at the client for longer. Issue: #4594. --- src/webui/webui.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 622540593..2652e0f08 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -292,6 +292,7 @@ page_static_file(http_connection_t *hc, const char *_remain, void *opaque) char buf[4096]; const char *gzip = NULL; int nogzip = 0; + int maxage = 10; /* Default age */ if(_remain == NULL) return HTTP_STATUS_NOT_FOUND; @@ -316,10 +317,14 @@ page_static_file(http_connection_t *hc, const char *_remain, void *opaque) content = "text/css; charset=UTF-8"; else if(!strcmp(postfix, "git")) nogzip = 1; - else if(!strcmp(postfix, "jpg")) - nogzip = 1; - else if(!strcmp(postfix, "png")) + else if(!strcmp(postfix, "jpg") || !strcmp(postfix, "png")) { nogzip = 1; + /* Increase amount of time in seconds that a client can cache + * images since they rarely change. This avoids clients + * requesting category icons frequently. + */ + maxage = 60 * 60; + } } fb_file *fp = fb_open(path, 0, (nogzip || gzip) ? 0 : 1); @@ -332,7 +337,7 @@ page_static_file(http_connection_t *hc, const char *_remain, void *opaque) gzip = "gzip"; http_send_begin(hc); - http_send_header(hc, 200, content, size, gzip, NULL, 10, 0, NULL, NULL); + http_send_header(hc, 200, content, size, gzip, NULL, maxage, 0, NULL, NULL); while (!fb_eof(fp)) { ssize_t c = fb_read(fp, buf, sizeof(buf)); if (c < 0) { -- 2.47.3