#minification #html #minify #sailfish

macro sailfish-minify

Hacky but simple minification support for sailfish, using html-minifier by default

3 unstable releases

0.2.2 Jun 15, 2024
0.2.1 Jun 15, 2024
0.2.0 Jun 13, 2024
0.1.0 Jun 11, 2024

#229 in Template engine

Download history 73/week @ 2024-06-06 212/week @ 2024-06-13 9/week @ 2024-06-20 2/week @ 2024-06-27 7/week @ 2024-07-04 5/week @ 2024-07-25

81 downloads per month

MIT license

12KB
238 lines

sailfish-minify

Hacky but simple minification support for sailfish, using html-minifier by default

IMPORTANT!

By default, sailfish-minify DOES also minify its components, however if you want to disable this behavior you can compile without "minifiy-components". Also, the components are minified with the "parent" template options, this behavior is however untested when there are multiple parents using the same component but using different minifier options.

Example

use sailfish::TemplateOnce;

#[derive(Debug, sailfish_minify::TemplateOnce)]
#[templ(path = "test.stpl")] // Notice the use of templ instead of template
// #[min_with(HTMLMinifier)] // Default is HTMLMinifier anyway
// #[min_with(Custom(html-minifier --collapse-whitespace))] // You can even use custom commands
struct MinifiedTestTemplate<'a> {
    s: &'a str
}

#[derive(Debug, TemplateOnce)]
#[template(path = "test.stpl")]
struct TestTemplate<'a> {
    s: &'a str
}

fn main() {
    println!("Unminified size: {} chars", TestTemplate { s: "test" }.render_once().unwrap().len());
    println!("Minified size: {} chars", MinifiedTestTemplate { s: "test" }.render_once().unwrap().len());
}

Output

Unminified size: 2238 chars
Minified size: 23 chars

Dependencies

~3–12MB
~113K SLoC