jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
641 stars 116 forks source link

Help browsers to cache static content #28

Closed JK-de closed 6 years ago

JK-de commented 6 years ago

Till now all static content (CSS, PNG, JS,...) is loaded from IoT-device on each page load. With additional headers 'Last-Modified' the static content is only loaded at the first time (and after 10 years). On refresh in browser (F5) a request is send with header 'Is-Modified-Since' and the IoT-device can answer with 304 (Not modified) to prevent sending all again. This improves loading time of pages dramatically! PyHTML-files are not affected/cached!

Note: Assuming the static files are really static and a new version gets a new name...

Tested with FireFox, Edge, Chrome (on Windows)

jczic commented 6 years ago

Ok yes, that's cool indeed ! Just, I think that's must be an option configurable (True/False) no ? (With a default and an optional date too ?)

JK-de commented 6 years ago

How should the config look like? A global variable like STATIC_CONTENT = True at top of MicroWebSrv or a setter function? I think default should be True for speed up page delivery.

Which date you send does not matter. Important is, that is always the same and is far in the past. Suggest an other fix date...

jczic commented 6 years ago

Yes, just a default variable set to True like : self.MaxWebSocketRecvLen = 1024 self.WebSocketThreaded = True self.AcceptWebSocketCallback = None

JK-de commented 6 years ago

Added microWebSrv.LetCacheStaticContentLevel to control the level of caching: 0=none, 1=cached, 2=cached even if F5