1JavaScript::Minifier(3)User Contributed Perl DocumentatioJnavaScript::Minifier(3)
2
3
4

NAME

6       JavaScript::Minifier - Perl extension for minifying JavaScript code
7

SYNOPSIS

9       To minify a JavaScript file and have the output written directly to
10       another file
11
12         use JavaScript::Minifier qw(minify);
13         open(INFILE, 'myScript.js') or die;
14         open(OUTFILE, '>myScript-min.js') or die;
15         minify(input => *INFILE, outfile => *OUTFILE);
16         close(INFILE);
17         close(OUTFILE);
18
19       To minify a JavaScript string literal. Note that by omitting the
20       outfile parameter a the minified code is returned as a string.
21
22         my minifiedJavaScript = minify(input => 'var x = 2;');
23
24       To include a copyright comment at the top of the minified code.
25
26         minify(input => 'var x = 2;', copyright => 'BSD License');
27
28       To treat ';;;' as '//' so that debugging code can be removed. This is a
29       common JavaScript convention for minification.
30
31         minify(input => 'var x = 2;', stripDebug => 1);
32
33       The "input" parameter is manditory. The "output", "copyright", and
34       "stripDebug" parameters are optional and can be used in any
35       combination.
36

DESCRIPTION

38       This module removes unnecessary whitespace from JavaScript code. The
39       primary requirement developing this module is to not break working
40       code: if working JavaScript is in input then working JavaScript is
41       output. It is ok if the input has missing semi-colons, snips like '++
42       +' or '12 .toString()', for example. Internet Explorer conditional
43       comments are copied to the output but the code inside these comments
44       will not be minified.
45
46       The ECMAScript specifications allow for many different whitespace
47       characters: space, horizontal tab, vertical tab, new line, carriage
48       return, form feed, and paragraph separator. This module understands all
49       of these as whitespace except for vertical tab and paragraph separator.
50       These two types of whitespace are not minimized.
51
52       For static JavaScript files, it is recommended that you minify during
53       the build stage of web deployment. If you minify on-the-fly then it
54       might be a good idea to cache the minified file. Minifying static files
55       on-the-fly repeatedly is wasteful.
56
57   EXPORT
58       None by default.
59
60       Exportable on demand: minifiy()
61

SEE ALSO

63       This project is developed using an SVN repository. To check out the
64       repository svn co http://dev.michaux.ca/svn/random/JavaScript-Minifier
65
66       This module is inspired by Douglas Crockford's JSMin:
67       http://www.crockford.com/javascript/jsmin.html
68
69       You may also be interested in the CSS::Minifier module also available
70       on CPAN.
71

AUTHORS

73       Peter Michaux, <petermichaux@gmail.com> Eric Herrera,
74       <herrera@10east.com>
75
77       Copyright (C) 2007 by Peter Michaux
78
79       This library is free software; you can redistribute it and/or modify it
80       under the same terms as Perl itself, either Perl version 5.8.6 or, at
81       your option, any later version of Perl 5 you may have available.
82
83
84
85perl v5.12.0                      2008-03-18           JavaScript::Minifier(3)
Impressum