meli icon indicating copy to clipboard operation
meli copied to clipboard

Precompressed option for Caddy FileServer

Open tanc opened this issue 3 years ago • 1 comments

A (hopefully) quick and easy feature request: Activate the precompressed option for the file_server directive in Caddy: https://caddyserver.com/docs/caddyfile/directives/file_server

Many frameworks allow the pre-compressing of static assets using Brotli and gzip and they are compiled out with [filename].br or similar extension. With Caddy's precompressed option its possible for Caddy to serve these instead of gzipping on the fly for improved performance.

I'm hoping its as easy as adding a line in https://github.com/getmeli/meli/blob/beta/server/src/caddy/definitions/handlers.d.ts#L111

The Caddy config should be:

file_server {
    precompressed br zstd gzip
}

This article explains it well: https://austindw.com/precompressed-assets-caddy/

What do you think?

tanc avatar Jul 13 '21 11:07 tanc

This is a great idea, seems easy to implement. Would you be up for a PR ? It should be around here:

// https://caddyserver.com/docs/json/apps/http/servers/routes/handle/encode/encodings/gzip/
// https://caddy.community/t/gzip-headers-when-using-encode-handler/11781
const gzipHandler = {
  handler: 'encode',
  encodings: {
    gzip: {},
  },
};

gempain avatar Jul 19 '21 23:07 gempain