This repository contains the Windows application jsmin.exe and the jsmin function. If you just want to use the jsmin command, just download jsmin.exe or compile yourself.
For Windows, please add the extension .exe
gcc jsmin.c lib/jsmin.c -o jsmin
This command erases extra whitespace and comments in the javascript code, making it one line and reducing the file size.
var sample = 100
log(sample)
// sample function
function log(num) {
if (num > 50) {
console.log("examples of use")
} else num += 20
}
var sample=100;log(sample);function log(num){if(num>50){console.log("examples of use")}else num+=20}
jsmin example.js
When a file name is specified in the command line argument of jsmin, a file such as example.min.js is created in the same directory, and the compression result is output to this file.
jsmin input.js -o output.js
You can also specify the destination file with the -o (--output) option. You can also write jsmin -o output.js input.js
.
jsmin example.js -w
In addition, the -w (--overwerite) option will overwrite the original file without creating a new file.You can also write jsmin -w example.js
.
jsmin -h
Use the -h (--help) option to see how to use jsmin
Usage: jsmin <file> [options...]
Options:
-o, --output <file> write to <file> instead of writing in '...min.js'
-w, --overwrite overwrite the file
-h, --help get help for commands
-v, --version show jsmin version
#include "lib/jsmin.h"
char *jsmin(char *code)
Parameters:
code
- Original javascript code
Returns:
Minified javascript code
Directory
├ example.c
└ lib
├ jsmin.h
└ jsmin.hc
// example.c
#include <stdio.h>
#include "lib/jsmin.h"
int main() {
FILE *fp = fopen("example.js", "r+");
// Get the contents of example.js
int i = 0;
char code[100000];
while((code[i] = fgetc(fp)) != EOF) i++;
code[i] = '\0';
char *result = jsmin(code); // <-- Minify the code here
// Overwrite the file
fputs(result, fp);
fclose(fp);
return 0;
}
gcc example.c lib/jsmin.c -o jsmin
This console application minifies example.js by overwriting it.