minify

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

minify

CircleCI branch community Go Report Card

Caddy plugin that implements minification on-the-fly for CSS, HTML, JSON, SVG and XML. It uses tdewolff's library so, let's thank him! You can download this plugin with Caddy on its official download page.

Syntax

minify paths...  {
    if          a cond b
    if_op       [and|or]
    disable     [js|css|html|json|svg|xml]
    minifier    option value
}
  • paths are space separated file paths to minify. If nothing is specified, the whole website will be minified.
  • if specifies a condition. Multiple ifs are AND-ed together by default. a and b are any string and may use request placeholders. cond is the condition, with possible values explained in rewrite (which also has an if statement).
  • if_op specifies how the ifs are evaluated; the default is and.
  • disable is used to indicate which minifiers to disable; by default, they're all activated.
  • minifier sets value for option on that minifier. When the option is true or false, its omission is trated as true. The possible options are described bellow.
Minifiers options
Minifier(s) Option Value Description
css, svg decimals number Preserves default attribute values.
xml, html keep_whitespace true|false Preserves whitespace between inline tags but still collapse multiple whitespace characters into one.
html keep_end_tags true|false Preserves all end tags.
html keep_document_tags true|false Preserve html, head and body tags.
html keep_default_attr_vals true|false Preserves default value attributes.
html keep_conditional_comments true|false Preserves all IE conditional comments.

For more information about what does each option and how each minifier work, read the documentation of tdewolff/minify.

Examples

Minify all of the supported files of the website:

minify

Only minify the contents of /assets folder:

minify /assets

Only minify css files:

minify {
    disable html svg json xml js
}

Minify the whole website except /api:

minify  {
    if {path} not_match ^(\/api).*
}

Minify the files of /assets folder except /assets/js:

minify /assets {
    if {path} not_match ^(\/assets\/js).*
}

Customize the minifier options:

minify {
    html keep_document_tags
    html keep_whitespace
}

Documentation

Overview

Package minify provides middlewarefor minifying each request before being sent to the browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Minify

type Minify struct {
	Next  httpserver.Handler
	Rules []httpserver.RequestMatcher
	Paths []string
}

Minify is an http.Handler that is able to minify the request before it's sent to the browser.

func (Minify) ServeHTTP

func (m Minify) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP is the main function of the whole plugin that routes every single request to its function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL