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
640 stars 115 forks source link

Added support for serving pre-compressed static files #56

Open camlee opened 5 years ago

camlee commented 5 years ago

If the request has the Accept-Encoding header, will look for files in webPath that are pre-compressed with the specified encoding(s) before falling back to the file without any compression. Sets the Content-Encoding header in the response appropriately.

For example, a request for /main.js with the Accept-Encoding header set to gzip, br will look for files in this order: main.js.gz, main.js.br, then main.js, No compression is done on the fly. main.js.gz should already be compressed with gzip and MicroWebSrv trusts this: it responds with the file as-is, setting the Content-Encoding header so that browsers will properly decode.

I'm using this to put only pre-compressed static files (HTML, CSS, Javascript) on my ESP32 to save a considerable amount of space. Also helps with performance as less data is transferred.

jczic commented 5 years ago

Thank you for this pull request :) I'll see that in few days!

ElHyperion commented 4 years ago

Any news about this pull request? I would certainly appreciate this functionality in MWS2

jczic commented 4 years ago

Hello @ElHyperion, I'll see that for MWS2 and respond to your mails as soon :) 👍

gitcnd commented 8 months ago

Is this project abandoned? What's with the 3+ year delay on including this extremely essential feature?

camlee commented 8 months ago

@gitcnd; I believe it is. The readme now links to a new repo, MicroWebSrv2: https://github.com/jczic/MicroWebSrv2 I haven't tried that myself yet.

gitcnd commented 8 months ago

I merged your changes into my fork - tested - works great!! Thanks for the awesome code :-)

https://github.com/gitcnd/MicroWebSrv

I also added a minified version (cuts the size in half - to just 18kb) which works as well

I only tested brotli (I don't care about the lesser compression of gzip)

MicroWebSrv2 looks interesting, but it's an incredible amount of bloat and seems to require a whole pile of extra files.

I am using it with this: https://github.com/vsolina/micropython-web-editor - and I'm pretty sure that replacing the web server with MicroWebSrv2 would end up breaking something anyhow...