KaisarCode

min.c

min.c - Asset Minifier

min.c provides conservative CSS, JavaScript, and HTML asset minification as a small C library and stdin/stdout CLI. It reduces payload size while preserving valid runtime behavior for common web asset pipelines.


CLI

Examples

Minify CSS:

echo 'body { color: red; }' | ./bin/x86_64/linux/min css

Minify JavaScript:

echo 'const x = 1; // comment' | ./bin/x86_64/linux/min js

Minify HTML:

echo '<div>  hello  </div>' | ./bin/x86_64/linux/min html

Parameters

ParameterDescription
cssMinify CSS input
jsMinify JavaScript input
htmlMinify HTML input
-h, --helpShow help and usage
-v, --versionShow version

Minification Behavior

CSS - removes block comments, collapses whitespace, removes trailing semicolons before }, and strips unit suffixes from zero values. Preserves quoted strings and calc() spacing.

JS - removes line and block comments, collapses whitespace between tokens. Preserves quoted strings, template literals, and regex literals. Regex detection is context-aware using the preceding significant character.

HTML - removes HTML comments, collapses whitespace between tokens. Preserves content inside <pre> and <textarea> verbatim. Preserves spaces adjacent to inline elements.


Public API

#include "min.h"

kc_min_t *ctx = kc_min_open();
char *output = NULL;

kc_min_set_mode(ctx, KC_MIN_MODE_CSS);
kc_min_exec(ctx, "body { color: red; }", &output);

kc_min_free(output);
kc_min_close(ctx);

Lifecycle

  • kc_min_open() - allocates and returns a new context owned by the caller.
  • kc_min_set_mode() - selects CSS, JavaScript, or HTML minification.
  • kc_min_mode() - converts a CLI mode name to an API mode constant.
  • kc_min_exec() - minifies a null-terminated input string and returns an owned output string.
  • kc_min_free() - releases output strings allocated by the library.
  • kc_min_close() - releases the context.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

The host build emits:

bin/{arch}/{platform}/min
bin/{arch}/{platform}/libmin.a
bin/{arch}/{platform}/libmin.so

Windows builds emit:

bin/{arch}/windows/min.exe
bin/{arch}/windows/libmin.dll
bin/{arch}/windows/libmin.dll.a

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

Beta Notice

This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.

If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.


Repo

You can download the repository and read the most up-to-date documentation directly from its official source.

GitHub: kaisarcode/min.c

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).