JavaSc...Packer(3pm)

πŸ“¦
version 2.12 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– 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 the copyright option. 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 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