getmeli / meli

Platform for deploying static sites and frontend applications easily. Automatic SSL, deploy previews, reverse proxy, and more.
Other
2.4k stars 97 forks source link

Precompressed option for Caddy FileServer #237

Open tanc opened 3 years ago

tanc commented 3 years ago

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?

gempain commented 3 years ago

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: {},
  },
};