Invaliating browser cache after UI selection change

This commit is contained in:
Blaz Kristan 2021-08-10 21:52:07 +02:00
parent dcfbf2b154
commit 602d04af82
3 changed files with 9 additions and 2 deletions

View File

@ -193,6 +193,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
strlcpy(serverDescription, request->arg(F("DS")).c_str(), 33); strlcpy(serverDescription, request->arg(F("DS")).c_str(), 33);
syncToggleReceive = request->hasArg(F("ST")); syncToggleReceive = request->hasArg(F("ST"));
#ifndef WLED_DISABLE_SIMPLE_UI #ifndef WLED_DISABLE_SIMPLE_UI
if (simplifiedUI ^ request->hasArg(F("SU"))) {
// UI selection changed, invalidate browser cache
cacheInvalidate++;
}
simplifiedUI = request->hasArg(F("SU")); simplifiedUI = request->hasArg(F("SU"));
#endif #endif
} }

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2108091 #define VERSION 2108101
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@ -282,6 +282,7 @@ WLED_GLOBAL byte briMultiplier _INIT(100); // % of brightness to set (t
WLED_GLOBAL char serverDescription[33] _INIT("WLED"); // Name of module WLED_GLOBAL char serverDescription[33] _INIT("WLED"); // Name of module
WLED_GLOBAL bool syncToggleReceive _INIT(false); // UIs which only have a single button for sync should toggle send+receive if this is true, only send otherwise WLED_GLOBAL bool syncToggleReceive _INIT(false); // UIs which only have a single button for sync should toggle send+receive if this is true, only send otherwise
WLED_GLOBAL bool simplifiedUI _INIT(false); // enable simplified UI WLED_GLOBAL bool simplifiedUI _INIT(false); // enable simplified UI
WLED_GLOBAL byte cacheInvalidate _INIT(0); // used to invalidate browser cache when switching from regular to simplified UI
// Sync CONFIG // Sync CONFIG
WLED_GLOBAL NodesMap Nodes; WLED_GLOBAL NodesMap Nodes;

View File

@ -285,12 +285,14 @@ bool handleIfNoneMatchCacheHeader(AsyncWebServerRequest* request)
void setStaticContentCacheHeaders(AsyncWebServerResponse *response) void setStaticContentCacheHeaders(AsyncWebServerResponse *response)
{ {
char tmp[12];
#ifndef WLED_DEBUG #ifndef WLED_DEBUG
response->addHeader(F("Cache-Control"),"max-age=604800"); // 7 day caching response->addHeader(F("Cache-Control"),"max-age=604800"); // 7 day caching
#else #else
response->addHeader(F("Cache-Control"),"no-store,max-age=0"); // prevent caching if debug build response->addHeader(F("Cache-Control"),"no-store,max-age=0"); // prevent caching if debug build
#endif #endif
response->addHeader(F("ETag"), String(VERSION)); sprintf_P(tmp, PSTR("%8d-%02x"), VERSION, cacheInvalidate);
response->addHeader(F("ETag"), tmp);
} }
void serveIndex(AsyncWebServerRequest* request) void serveIndex(AsyncWebServerRequest* request)