MicroWebSrv icon indicating copy to clipboard operation
MicroWebSrv copied to clipboard

Added support for serving pre-compressed static files

Open camlee opened this issue 5 years ago • 6 comments

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.

camlee avatar Jun 22 '19 05:06 camlee

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

jczic avatar Jul 06 '19 00:07 jczic

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

ElHyperion avatar Feb 10 '20 12:02 ElHyperion

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

jczic avatar Feb 10 '20 16:02 jczic

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

gitcnd avatar Oct 28 '23 02:10 gitcnd

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

camlee avatar Oct 28 '23 02:10 camlee

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

gitcnd avatar Oct 28 '23 10:10 gitcnd