1JavaScript::Minifier::XUSs(e3r)Contributed Perl DocumentJaatviaoSncript::Minifier::XS(3)
2
3
4

NAME

6       JavaScript::Minifier::XS - XS based JavaScript minifier
7

SYNOPSIS

9         use JavaScript::Minifier::XS qw(minify);
10         my $js       = '...';
11         my $minified = minify($js);
12

DESCRIPTION

14       "JavaScript::Minifier::XS" is a JavaScript "minifier"; its designed to
15       remove unnecessary whitespace and comments from JavaScript files, which
16       also not breaking the JavaScript.
17
18       "JavaScript::Minifier::XS" is similar in function to
19       "JavaScript::Minifier", but is substantially faster as its written in
20       XS and not just pure Perl.
21

METHODS

23       minify($js)
24           Minifies the given $js, returning the minified JavaScript back to
25           the caller.
26

HOW IT WORKS

28       "JavaScript::Minifier::XS" minifies the JavaScript by removing
29       unnecessary whitespace from JavaScript documents.  Comments (both block
30       and line) are also removed, except when (a) they contain the word
31       "copyright" in them, or (b) they're needed to implement "IE Conditional
32       Compilation".
33
34       Internally, the minification process is done by taking multiple passes
35       through the JavaScript document:
36
37   Pass 1: Tokenize
38       First, we go through and parse the JavaScript document into a series of
39       tokens internally.  The tokenizing process does not check to make sure
40       you've got syntactically valid JavaScript, it just breaks up the text
41       into a stream of tokens suitable for processing by the subsequent
42       stages.
43
44   Pass 2: Collapse
45       We then march through the token list and collapse certain tokens down
46       to their smallest possible representation.  If they're still included
47       in the final results we only want to include them at their shortest.
48
49       Whitespace
50           Runs of multiple whitespace characters are reduced down to a single
51           whitespace character.  If the whitespace contains any "end of line"
52           (EOL) characters, then the end result is the first EOL character
53           encountered.  Otherwise, the result is the first whitespace
54           character in the run.
55
56   Pass 3: Pruning
57       We then go back through the token list and prune and remove unnecessary
58       tokens.
59
60       Whitespace
61           Wherever possible, whitespace is removed; before+after comment
62           blocks, and before+after various symbols/sigils.
63
64       Comments
65           Comments that are either (a) IE conditional compilation comments,
66           or that (b) contain the word "copyright" in them are preserved.
67           All other comments (line and block) are removed.
68
69       Everything else
70           We keep everything else; identifiers, quoted literal strings,
71           symbols/sigils, etc.
72
73   Pass 4: Re-assembly
74       Lastly, we go back through the token list and re-assemble it all back
75       into a single JavaScript string, which is then returned back to the
76       caller.
77

AUTHOR

79       Graham TerMarsch (cpan@howlingfrog.com)
80
82       Copyright (C) 2007-, Graham TerMarsch.  All Rights Reserved.
83
84       This is free software; you can redistribute it and/or modify it under
85       the same license as Perl itself.
86

SEE ALSO

88       "JavaScript::Minifier".
89
90
91
92perl v5.32.1                      2021-02-08       JavaScript::Minifier::XS(3)
Impressum