mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-19 17:26:38 +00:00
Cache style.css on the browser if served from flash #246
This commit is contained in:
parent
e3b20858a0
commit
6013ccd452
@ -914,6 +914,9 @@ static int handleFileRead(String path)
|
|||||||
path += F("index.htm");
|
path += F("index.htm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String style_css = F("/style.css");
|
||||||
|
bool is_style_css = (path == style_css);
|
||||||
|
|
||||||
String pathWithGz = path + F(".gz");
|
String pathWithGz = path + F(".gz");
|
||||||
if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) {
|
if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) {
|
||||||
|
|
||||||
@ -945,6 +948,9 @@ static int handleFileRead(String path)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// Only styles.css can be cached
|
||||||
|
if(is_style_css) webSendCacheHeader(file.size(), 3600);
|
||||||
|
|
||||||
// Stream other files directly from filesystem
|
// Stream other files directly from filesystem
|
||||||
webServer.streamFile(file, contentType);
|
webServer.streamFile(file, contentType);
|
||||||
file.close();
|
file.close();
|
||||||
@ -962,7 +968,7 @@ static int handleFileRead(String path)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_IDF_TARGET_ESP32)
|
#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;
|
size_t size = STYLE_CSS_GZ_END - STYLE_CSS_GZ_START;
|
||||||
webServer.sendHeader(F("Content-Encoding"), F("gzip"));
|
webServer.sendHeader(F("Content-Encoding"), F("gzip"));
|
||||||
return webSendCached(200, PSTR("text/css"), (const char*)STYLE_CSS_GZ_START, size); // OK
|
return webSendCached(200, PSTR("text/css"), (const char*)STYLE_CSS_GZ_START, size); // OK
|
||||||
|
Loading…
x
Reference in New Issue
Block a user