-
Couldn't load subscription status.
- Fork 7.7k
Mor info on the WebServer::serveStatic method please #11728
-
I'm running a websever on an esp32s3 and using the server.serveStatic method to deliver images to the requesting browser.
ex: server.serveStatic("/water_press_warn", LittleFS, "/water_press_warn_v2.png");
I'm trying to implement a caching control header so that the image doesnt need to reload everytime a user logs onto the server.
For example: Cache-Control: max-age=31536000, immutable
In researching the webserver library, there seems to be an additional argument available in the serverStatic method to allow for this:
void serveStatic(const char *uri, fs::FS &fs, const char *path, const char *cache_header = NULL);
I've tried to implement without success as I'm unsure that I'm using the correct syntax.
ex: server.serveStatic("/water_press_low", LittleFS, "/water_press_low_v2.png", "max-age = 315360000");
Would appreciate some guidance on the exact syntax I need to use for this to work as I cant find it in the documentation or the example files...
Thanks in advance for any help...
@me-no-dev, as you are very knowlegeable with this library, if you can spare 30 seconds to respond it would really be appreciated...
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Changed the last argument to "max-age = 15, immutable" and tested with dev tools. Reloaded the page within 15 seconds of initial load (see bellow) and images loaded from cache as expected. So I can now confirm that this 3rd argument of the serveStatic indeed works fine...
Screenshot 2025年08月15日 104029Beta Was this translation helpful? Give feedback.