ETag support for WebServer by imwhocodes · Pull Request #7709 · esp8266/Arduino
Thanks for the appreciation
Nice, it allows to reduce network activity !
I have a number of questions:Is this a feature that is only useful while developing web sites, or is it also useful in production ?
IMHO it depends on the situation:
Etagcache control tag always do a round trip for the requested page, but the response is only a status code (304) if the file is unchangedmax-agecache control tag most of the time do not even ask for the page, but too short of a time and you don't cache, too long and you can miss updates (or the browser can ignore the timeout and ask the page again anyway)
But the two cache control methods could be used together for maximum caching (in the next implementation?)
If so, should it be transparently enabled ?
- using ESP8266WebServer = esp8266webserver::ESP8266WebServerTemplate<WiFiServer>; + using ESP8266WebServer = esp8266webserver::ESP8266WebServerETagTemplate<WiFiServer>;or with an option (arduino menu and / or global define) ?
using ESP8266WebServerNoETag = esp8266webserver::ESP8266WebServerTemplate<WiFiServer>; using ESP8266WebServerETag = esp8266webserver::ESP8266WebServerETagTemplate<WiFiServer>; #if ETAG_ENABLED using ESP8266WebServer = ESP8266WebServerETag; #else using ESP8266WebServer = ESP8266WebServerNoETag; #endifor on sketch request (as proposed by your PR) ?
using ESP8266WebServer = esp8266webserver::ESP8266WebServerTemplate<WiFiServer>; using ESP8266WebServerETag = esp8266webserver::ESP8266WebServerETagTemplate<WiFiServer>;
This is a good question...
Implementing it transparently would be very cool but I didn't because it would be a breaking change:
- It increase the memory footprint (a
Stringof size 24) for every statically served page (a locally stored Etag string plus another possible Etag parsed from browser request header during handling) - For now it don't support the dynamic append of
index.htmorindex.htmlif requested page is a folder (being Etag calculated only once)
I opted for the on sketch request for backward compatibility and for keeping old code excepted behaviour, but being this PR on the 3.x branch maybe can this different behaviour acceptable?
Does it slow down web requets on big files since it is calculated on every request ?
Did you think of caching the results ?
Actually as implemented right now the hash in only computed once when you call ESP8266WebServerETag::serveStaticETag, then StaticRequestETagHandler::handle only check if the browser request Etag is the same as the one before computed
An option for a transparent implementation could be to compute the ETag every time a static page is requested, it would:
- keep the excepted behaviour of dynamic
index.htmlif page requested is folder ofESP8266WebServer - smaller memory footprint than ESP8266WebServerEtag
Etagandmax-ageat the same time- but Hashing of the file every time
In this case/implementation a (arduino menu and / or global define) would be ideal