JavaSc...nifier(3pm)
π JavaScript::Minifier β the NAME situation π
okay so bestie, this is JavaScript::Minifier, a Perl extension that minifies JavaScript code. that's it, that's the whole vibe. it's from the User Contributed Perl Documentation collection, and it is so ready to make your JS files skinny. π
β¨ SYNOPSIS β¨
πΈ minify a whole file, output straight into another file
use JavaScript::Minifier qw(minify);
open(my $in, 'myScript.js') or die;
open(my $out, '>', 'myScript-min.js') or die;
minify(input => $in, outfile => $out);
close($in);
close($out);
π¦ minify a JavaScript string literal
the tea here: if you leave out the outfile param, the minified code comes back to you as a string. no file, just vibes.
my $minifiedJavaScript = minify(input => 'var x = 2;');
π drop a copyright comment at the top of the minified code
minify(input => 'var x = 2;', copyright => 'BSD License');
π
treat ';;;' as '//' so debugging code can get yeeted
this is a common JavaScript convention for minification, iykyk.
minify(input => 'var x = 2;', stripDebug => 1);
so real talk: the "input" parameter is mandatory, no skipping it, it's the main character. "output", "copyright", and "stripDebug" are optional and you can mix and match them however you want, any combination, go off. π
π DESCRIPTION π
this module strips out unnecessary whitespace from JavaScript code. and the whole reason it exists, the primary requirement it was developed around, is to not break working code. like, if working JavaScript goes in, working JavaScript comes out. periodt. π―
and it's totally fine if your input is a little chaotic, ngl:
- missing semi-colons? fine.
- snips like
'++ +'? fine. '12 .toString()'? also fine.
Internet Explorer conditional comments get copied over to the output, but heads up bestie, the code inside those comments does not get minified. π«Ά
now, the ECMAScript specifications allow for a lot of different whitespace characters: space, horizontal tab, vertical tab, new line, carriage return, form feed, and paragraph separator. this module understands all of them as whitespace β except for vertical tab and paragraph separator. those two types of whitespace are not minimized. noted. π
for static JavaScript files, the recommendation is to minify during the build stage of web deployment. if you're minifying on-the-fly instead, it might be a good idea to cache that minified file. because minifying static files on-the-fly over and over again is just wasteful, fr fr. π
π EXPORT π
Exported by default: minifiy()
not me pointing out that the manpage literally spells it minifiy() β that's what's written, so that's what you get. π
π SEE ALSO π
this module is inspired by Douglas Crockford's JSMin: <http://www.crockford.com/javascript/jsmin.html>
you may also be interested in the CSS::Minifier module, also available on CPAN. two minifiers, bestie, one for each language, slay. π₯
π§ REPOSITORY π§
you can grab the latest source code and submit bug reports on the github repository for this module: <https://github.com/zoffixznet/JavaScript-Minifier>
π MAINTAINER π
Zoffix Znet "<zoffix@cpan.org>" <https://metacpan.org/author/ZOFFIX>
πΈ AUTHORS πΈ
Peter Michaux, <petermichaux@gmail.com>
Eric Herrera, <herrera@10east.com>
π CONTRIBUTORS π
Miller 'tmhall' Hall
ΠΡΡΠ΅ΡΠ»Π°Π² 'vti' Π’ΠΈΡ Π°Π½ΠΎΠ²ΡΠΊΠΈΠΉ
Fedor A. 'faf' Fetisov
π COPYRIGHT AND LICENSE π
Copyright (C) 2007 by Peter Michaux
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie π«Ά this was perl v5.36.0, dated 2022-11-20, brought to you by the User Contributed Perl Documentation crew β now go forth and minify, you absolute icon β¨π
π¦ where this page comes from
- debian bookworm: libjavascript-minifier-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libjavascript-minifier-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libjavascript-minifier-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjavascript-minifier-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjavascript-minifier-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms