Open ofekd opened 1 month ago
Setting the header for pre-compressed files sounds good!
I'm curious about compressing on the fly. It seems very wasteful to do this every time, so I'm not sure it's something I would want to encourage in Wisp itself.
Compressing on the fly is unavoidable for some dynamic content. I had a simple backend serving a lustre-rendered html + some inlined tailwind. It was ~65kb uncompressed, and ~7.5kb compressed with zlib.
When benchmarking, the network bandwidth on the server got saturated way before the CPU, which is quite a waste. Compression solved that completely at about 10-20% CPU cost, which led to overall better utilization. I bet if I had used Erlang's brotli library it would have been much easier on the CPU.
Since the exact compression setup is different for every app (some would do it on the BE, some would do on the proxy, some would compress on the BE then cache at the proxy, etc), maybe it is better to leave it to the users to implement as middleware.
This is fairly simple to do when writing your own middleware, but that serve_static
situation -- or really, extending any other middleware -- is tricky. I don't know if this calls for tweaking the middleware API, or is just a matter of addressing the serve_static
middleware specifically
I was talking about it being wasteful in the context of serve static specifically. Having a package that provides compression sounds like a great idea to me!
To reduce request size, often the body is compressed. A mechanism that supports this is currently missing from Wisp.
I am not quite sure what scope of a solution is a good fit for Wisp. A full flow will be:
accept-encoding
headercontent-encoding
header to indicate the compression for responses compressed on the flySteps 1 through 3 are fairly straightforward to do on top of wisp:
But there's no clear way to achieve step 4
My current work around is to hard-code the file names:
But even beyond the hard-coding of file name, this checks every response