Skip to content

devetek/caddyserver-minifier

Repository files navigation

Caddyserver v2 Plugin - Minifier

Caddyserver v2 plugin that implements minification on-the-fly for CSS, HTML, JSON, SVG and XML. It uses tdewolff's library so, let's thank him!.

Syntax

Because this directive does not come standard with Caddy, you may use route to order it the way you want. For example:

Minimum configuration:

http://localhost:9200 {
	route {
		minifier
		reverse_proxy localhost:8097
	}
}

Partial configuration:

http://localhost:9200 {
	route {
		minifier {
			html {
				KeepDefaultAttrVals true
				KeepDocumentTags true
				KeepEndTags true
				KeepQuotes true
			}
		}
		reverse_proxy localhost:8097
	}
}

Full configuration:

http://localhost:9200 {
	route {
		minifier {
			html {
				KeepConditionalComments true
				KeepSpecialComments true
				KeepComments true
				KeepWhitespace true
				KeepDefaultAttrVals true
				KeepDocumentTags true
				KeepEndTags true
				KeepQuotes true
			}
		}
		reverse_proxy localhost:8097
	}
}

Todo

  • Support for another Content-Type (css, js, etc):
minifier {
 js
 css
}

Credit

Special thanks to @mholt for making a good documentation on how to use unstandard Caddy plugins, mholt/caddy-webdav