Add Cache-Control to index
This commit is contained in:
parent
75c219d6c6
commit
c24d574f90
@ -229,14 +229,32 @@ void serveIndexOrWelcome(AsyncWebServerRequest *request)
|
||||
}
|
||||
}
|
||||
|
||||
bool handleIfNoneMatchCacheHeader(AsyncWebServerRequest* request)
|
||||
{
|
||||
AsyncWebHeader* header = request->getHeader("If-None-Match");
|
||||
if (header && header->value() == String(VERSION)) {
|
||||
request->send(304);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool setStaticContentCacheHeaders(AsyncWebServerResponse *response)
|
||||
{
|
||||
response->addHeader(F("Cache-Control"),"max-age=2592000");
|
||||
response->addHeader(F("ETag"), String(VERSION));
|
||||
}
|
||||
|
||||
void serveIndex(AsyncWebServerRequest* request)
|
||||
{
|
||||
if (handleFileRead(request, "/index.htm")) return;
|
||||
|
||||
if (handleIfNoneMatchCacheHeader(request)) return;
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", PAGE_index, PAGE_index_L);
|
||||
|
||||
response->addHeader(F("Content-Encoding"),"gzip");
|
||||
setStaticContentCacheHeaders(response);
|
||||
|
||||
request->send(response);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user