From 6013ccd4529e8050d70c865d73aeca83aa011c73 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:20:48 +0100 Subject: [PATCH] Cache style.css on the browser if served from flash #246 --- src/sys/svc/hasp_http.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 6e680a23..481b5164 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -913,6 +913,9 @@ static int handleFileRead(String path) if(path.endsWith("/")) { path += F("index.htm"); } + + String style_css = F("/style.css"); + bool is_style_css = (path == style_css); String pathWithGz = path + F(".gz"); if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) { @@ -945,6 +948,9 @@ static int handleFileRead(String path) } else { + // Only styles.css can be cached + if(is_style_css) webSendCacheHeader(file.size(), 3600); + // Stream other files directly from filesystem webServer.streamFile(file, contentType); file.close(); @@ -962,7 +968,7 @@ static int handleFileRead(String path) #endif #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_IDF_TARGET_ESP32) - if(path == F("/style.css")) { + if(path == style_css) { size_t size = STYLE_CSS_GZ_END - STYLE_CSS_GZ_START; webServer.sendHeader(F("Content-Encoding"), F("gzip")); return webSendCached(200, PSTR("text/css"), (const char*)STYLE_CSS_GZ_START, size); // OK