|
| 1 | +# NAME |
| 2 | + |
| 3 | +Apache2::Filter::Minifier::JavaScript - JS minifying output filter |
| 4 | + |
| 5 | +# SYNOPSIS |
| 6 | + |
| 7 | +```perl |
| 8 | +<LocationMatch "\.js$"> |
| 9 | + PerlOutputFilterHandler Apache2::Filter::Minifier::JavaScript |
| 10 | +
|
| 11 | + # if you need to supplement MIME-Type list |
| 12 | + PerlSetVar JsMimeType text/json |
| 13 | +
|
| 14 | + # if you want to explicitly specify the minifier to use |
| 15 | + #PerlSetVar JsMinifier JavaScript::Minifier::XS |
| 16 | + #PerlSetVar JsMinifier JavaScript::Minifier |
| 17 | + #PerlSetVar JsMinifier MY::Minifier::function |
| 18 | +</LocationMatch> |
| 19 | +``` |
| 20 | +
|
| 21 | +# DESCRIPTION |
| 22 | +
|
| 23 | +`Apache2::Filter::Minifier::JavaScript` is a Mod\_perl2 output filter which |
| 24 | +minifies JavaScript using `JavaScript::Minifier` or |
| 25 | +`JavaScript::Minifier::XS`. |
| 26 | +
|
| 27 | +Only JavaScript documents are minified, all others are passed through |
| 28 | +unaltered. `Apache2::Filter::Minifier::JavaScript` comes with a list of |
| 29 | +several known acceptable MIME-Types for JavaScript documents, but you can |
| 30 | +supplement that list yourself by setting the `JsMimeType` PerlVar |
| 31 | +appropriately (use `PerlSetVar` for a single new MIME-Type, or `PerlAddVar` |
| 32 | +when you want to add multiple MIME-Types). |
| 33 | +
|
| 34 | +Given a choice, using `JavaScript::Minifier::XS` is preferred over |
| 35 | +`JavaScript::Minifier`, but we'll use whichever one you've got available. If |
| 36 | +you want to explicitly specify which minifier you want to use, set the |
| 37 | +`JsMinifier` PerlVar to the name of the package/function that implements the |
| 38 | +minifier. Minification functions are expected to accept a single parameter |
| 39 | +(the JavaScript to be minified) and to return the minified JavaScript on |
| 40 | +completion. If you specify a package name, we look for a `minify()` function |
| 41 | +in that package. |
| 42 | +
|
| 43 | +## Caching |
| 44 | +
|
| 45 | +Minification does require additional CPU resources, and it is recommended that |
| 46 | +you use some sort of cache in order to keep this to a minimum. |
| 47 | +
|
| 48 | +Being that you're already running Apache2, though, here's some examples of a |
| 49 | +mod\_cache setup: |
| 50 | +
|
| 51 | +Disk Cache |
| 52 | +
|
| 53 | +``` |
| 54 | +# Cache root directory |
| 55 | +CacheRoot /path/to/your/disk/cache |
| 56 | +# Enable cache for "/js/" location |
| 57 | +CacheEnable disk /js/ |
| 58 | +``` |
| 59 | +
|
| 60 | +Memory Cache |
| 61 | +
|
| 62 | +``` |
| 63 | +# Cache size: 4 MBytes |
| 64 | +MCacheSize 4096 |
| 65 | +# Min object size: 128 Bytes |
| 66 | +MCacheMinObjectSize 128 |
| 67 | +# Max object size: 512 KBytes |
| 68 | +MCacheMaxObjectSize 524288 |
| 69 | +# Enable cache for "/js/" location |
| 70 | +CacheEnable mem /js/ |
| 71 | +``` |
| 72 | +
|
| 73 | +# METHODS |
| 74 | +
|
| 75 | +- handler($filter) |
| 76 | +
|
| 77 | + JavaScript minification output filter. |
| 78 | +
|
| 79 | +# AUTHOR |
| 80 | +
|
| 81 | +Graham TerMarsch (cpan@howlingfrog.com) |
| 82 | +
|
| 83 | +Many thanks to Geoffrey Young for writing `Apache::Clean`, from which several |
| 84 | +things were lifted. :) |
| 85 | +
|
| 86 | +# COPYRIGHT |
| 87 | +
|
| 88 | +Copyright (C) 2007, Graham TerMarsch. All Rights Reserved. |
| 89 | +
|
| 90 | +This is free software; you can redistribute it and/or modify it under the same |
| 91 | +license as Perl itself. |
| 92 | +
|
| 93 | +# SEE ALSO |
| 94 | +
|
| 95 | +[JavaScript::Minifier](https://metacpan.org/pod/JavaScript%3A%3AMinifier), |
| 96 | +[JavaScript::Minifier::XS](https://metacpan.org/pod/JavaScript%3A%3AMinifier%3A%3AXS), |
| 97 | +[Apache2::Filter::Minifier::CSS](https://metacpan.org/pod/Apache2%3A%3AFilter%3A%3AMinifier%3A%3ACSS), |
| 98 | +[Apache::Clean](https://metacpan.org/pod/Apache%3A%3AClean). |
0 commit comments