JavaSc...nifier(3pm)

πŸ“¦
version 1.16 Β· 7 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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;');
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 (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