Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mor info on the ‎WebServer::serveStatic method please #11728

Closed Unanswered
AIoT-Consulting asked this question in Q&A
Discussion options

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...

You must be logged in to vote

Replies: 1 comment

Comment options

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日 104029
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /