JavaSc...Packer(3pm)
π JavaScript::Packer β the manual, but make it cute π
okay bestie, listen. This page you're reading is JavaSc...Packer(3pm) from the User Contributed Perl Documentation section of the manual. Yep, the name got squished with dots because terminals are dramatic, but it's really JavaScript::Packer and it's here to make your JavaScript smol. π
β¨ NAME β¨
JavaScript::Packer β it's a Perl version of Dean Edwards' Packer.js. That's it, that's the whole name section, and honestly? Iconic.
πΈ VERSION πΈ
Version 2.12 β she's been around a minute and she still slays. π
π¦ DESCRIPTION π¦
A JavaScript Compressor. Yes, really, that's the whole thing.
This module is an adaptation of Dean Edwards' Packer.js.
Additional information: http://dean.edwards.name/packer/ β go look, bestie, it's the origin story.
π SYNOPSIS π
Get her loaded up first:
use JavaScript::Packer;
my $packer = JavaScript::Packer->init();
$packer->minify( $javascript, $opts );
Want a scalar back instead of mutating your input in place? Say less β just use it in scalar context (like in example 2 down below π«Ά):
my $ret = $packer->minify( $javascript, $opts );
And for backward compatibility β because we respect our elders β you can still call 'minify' as a plain function:
JavaScript::Packer::minify( $javascript, $opts );
Now the important bits, no cap: the first argument must be a scalarref of javascript-code.
Second argument must be a hashref of options. Possible options are:
compressβ defines the compression level. Possible values are'clean','shrink','obfuscate'and'best'. Default value is'clean'.'best'uses'shrink'or'obfuscate'depending on which result is shorter. This is recommended because especially when compressing short scripts the result will exceed the input if compression level is'obfuscate'. π (yes, you can make your file BIGGER, be careful babe)copyrightβ you can add a copyright notice at the top of the script. Cute, legal, iconic. πremove_copyrightβ if there is a copyright notice in a comment it will only be removed if this option is set to a true value. Otherwise the first comment that contains the word "copyright" will be added at the top of the packed script. A copyright comment will be overwritten by a copyright notice defined with thecopyrightoption. The vibes must be preserved, bestie.no_compress_commentβ if not set to a true value it is allowed to set a JavaScript comment that prevents the input being packed or defines a compression level. πβ¨
/* JavaScript::Packer _no_compress_ */
/* JavaScript::Packer shrink */
π EXAMPLES π
β Example 1 β Common usage.
The classic. The blueprint. The moment. π
#!/usr/bin/perl
use strict;
use warnings;
use JavaScript::Packer;
my $packer = JavaScript::Packer->init();
open( UNCOMPRESSED, 'uncompressed.js' );
open( COMPRESSED, '>compressed.js' );
my $js = join( '', <UNCOMPRESSED> );
$packer->minify( \$js, { compress => 'best' } );
print COMPRESSED $js;
close(UNCOMPRESSED);
close(COMPRESSED);
β Example 2 β A scalar is requested by the context.
Not me calling it in scalar context so my input stays untouched π The input will remain unchanged. Slay.
#!/usr/bin/perl
use strict;
use warnings;
use JavaScript::Packer;
my $packer = JavaScript::Packer->init();
open( UNCOMPRESSED, 'uncompressed.js' );
open( COMPRESSED, '>compressed.js' );
my $uncompressed = join( '', <UNCOMPRESSED> );
my $compressed = $packer->minify( \$uncompressed, { compress => 'best' } );
print COMPRESSED $compressed;
close(UNCOMPRESSED);
close(COMPRESSED);
π AUTHOR π
Merten Falk, "<nevesenin at cpan.org>". Now maintained by Lee Johnson (LEEJO). Two legends, one module, fr fr.
π BUGS AND CAVEATS π
READ THIS ONE, BESTIE. This module will break code that relies on ASI β see https://github.com/leejo/javascript-packer-perl/issues/5 for more information. ASI = automatic semicolon insertion, and no, she does not play nice with it.
This module uses regular expressions to parse the JavaScript so is prone to bugs and edge cases, especially when the JavaScript standard is updated. π Regex parsing a whole language... the audacity, the bravery, the chaos.
Please report any bugs or feature requests through the web interface at http://github.com/leejo/javascript-packer-perl/issues. Tell her what's wrong, she can take it. π«Ά
π§ SUPPORT π§
You can find documentation for this module with the perldoc command.
perldoc JavaScript::Packer
That's it. That's the support. Type it in and let the manpage hold your hand. β¨
π COPYRIGHT & LICENSE π
Copyright 2008 - 2012 Merten Falk, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
And that's the whole page, bestie β written up against perl v5.40.1 and dated 2025-05-16 in the classic JavaSc...Packer(3pm) style. Go compress something. Mwah. π
π¦ where this page comes from
- debian trixie: libjavascript-packer-perl 2.12+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjavascript-packer-perl 2.12+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjavascript-packer-perl 2.12+dfsg-1 Β· 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