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         $minified = minify($js);
11

DESCRIPTION

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

METHODS

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

HOW IT WORKS

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

AUTHOR

78       Graham TerMarsch (cpan@howlingfrog.com)
79

REPORTING BUGS

81       Please report bugs via RT
82       (<http://rt.cpan.org/Dist/Display.html?Queue=JavaScript::Minifier::XS>),
83       and be sure to include the JavaScript that you're having troubles
84       minifying.
85
87       Copyright (C) 2007-2008, Graham TerMarsch.  All Rights Reserved.
88
89       This is free software; you can redistribute it and/or modify it under
90       the same license as Perl itself.
91

SEE ALSO

93       "JavaScript::Minifier".
94
95
96
97perl v5.28.1                      2019-02-02       JavaScript::Minifier::XS(3)
Impressum