const-css-minify

Crates.ioconst-css-minify
lib.rsconst-css-minify
version0.1.5
sourcesrc
created_at2024-05-04 06:55:40.266216
updated_at2024-05-07 11:28:02.551277
descriptionInclude a minified css file as an inline const in your high-performance compiled web application
homepage
repositoryhttps://github.com/scpso/const-css-minify
max_upload_size
id1229436
size72,890
(scpso)

documentation

README

const-css-minify

github crates.io docs.rs

Include a minified css file as an inline const in your high-performance compiled web application.

use const_css_minify::minify;

const CSS: &str = minify!("./path/to/style.css");

const_css_minify is not a good solution if your css changes out-of-step with your binary, as you will not be able to change the css without recompiling your application.

const_css_minify will:

  • remove unneeded whitespace and linebreaks
  • remove comments
  • remove unneeded trailing semicolon in each declaration block
  • opportunistically minify literal hex colors if and only if they can be expressed identically with a 3 character code (e.g. #ffffff will be substituted with #fff but #fffffe and #ffffffff will be left untouched)
  • minify colors specified by rgb function (e.g. rgb(255, 255, 254) will be substituted with #fffffe, and rgb(255, 255, 255) with #fff)
  • silently ignore any actual css syntax errors originating in your source file, and in so doing possibly elicit slightly different failure modes from renderers by altering the placement of whitespace around misplaced operators.

const_css_minify will not:

  • compress your css using gz, br or deflate
  • change the semantic meaning of your semantically valid css
  • make any substitutions other than identical literal colors
  • do anything at all to alert you to invalid css - it's not truly parsing the css, just scanning for and removing characters it identifies as unnecessary.

This project is licensed under the terms of the MIT License.

Commit count: 7

cargo fmt