1 .. -*- coding: utf-8 -*- 2 3 =========================================== 4 rJSmin - A Javascript Minifier For Python 5 =========================================== 6 7 TABLE OF CONTENTS 8 ----------------- 9 10 1. Introduction 11 2. Copyright and License 12 3. System Requirements 13 4. Installation 14 5. Documentation 15 6. Bugs 16 7. Author Information 17 18 19 INTRODUCTION 20 ------------ 21 22 rJSmin is a javascript minifier written in python. 23 24 The minifier is based on the semantics of `jsmin.c by Douglas Crockford`_\. 25 26 The module is a re-implementation aiming for speed, so it can be used at 27 runtime (rather than during a preprocessing step). Usually it produces the 28 same results as the original ``jsmin.c``. It differs in the following ways: 29 30 - there is no error detection: unterminated string, regex and comment 31 literals are treated as regular javascript code and minified as such. 32 - Control characters inside string and regex literals are left untouched; they 33 are not converted to spaces (nor to \\n) 34 - Newline characters are not allowed inside string and regex literals, except 35 for line continuations in string literals (ECMA-5). 36 - "return /regex/" is recognized correctly. 37 - Line terminators after regex literals are handled more sensibly 38 - "+ +" and "- -" sequences are not collapsed to '++' or '--' 39 - Newlines before ! operators are removed more sensibly 40 - Comments starting with an exclamation mark (``!``) can be kept optionally 41 - rJSmin does not handle streams, but only complete strings. (However, the 42 module provides a "streamy" interface). 43 44 Since most parts of the logic are handled by the regex engine it's way faster 45 than the original python port of ``jsmin.c`` by Baruch Even. The speed factor 46 varies between about 6 and 55 depending on input and python version (it gets 47 faster the more compressed the input already is). Compared to the 48 speed-refactored python port by Dave St.Germain the performance gain is less 49 dramatic but still between 3 and 50 (for huge inputs). See the docs/BENCHMARKS 50 file for details. 51 52 rjsmin.c is a reimplementation of rjsmin.py in C and speeds it up even more. 53 54 .. _jsmin.c by Douglas Crockford: http://www.crockford.com/javascript/jsmin.c 55 56 57 COPYRIGHT AND LICENSE 58 --------------------- 59 60 Copyright 2011 - 2015 61 Andr Malo or his licensors, as applicable. 62 63 The whole package (except for the files in the bench/ directory) 64 is distributed under the Apache License Version 2.0. You'll find a copy in the 65 root directory of the distribution or online at: 66 <http://www.apache.org/licenses/LICENSE-2.0>. 67 68 69 SYSTEM REQUIREMENTS 70 ------------------- 71 72 Both python 2 (>=2.4) and python 3 are supported. 73 74 75 INSTALLATION 76 ------------ 77 78 Using pip 79 ~~~~~~~~~ 80 81 $ pip install rjsmin 82 83 84 Using distutils 85 ~~~~~~~~~~~~~~~ 86 87 $ python setup.py install 88 89 The following extra options to the install command may be of interest: 90 91 --without-c-extensions Don't install C extensions 92 --without-docs Do not install documentation files 93 94 95 Drop-in 96 ~~~~~~~ 97 98 rJSmin effectively consists of two files: rjsmin.py and rjsmin.c, the 99 latter being entirely optional. So, for simple integration you can just 100 copy rjsmin.py into your project and use it. 101 102 103 DOCUMENTATION 104 ------------- 105 106 A generated API documentation is available in the docs/apidoc/ directory. 107 But you can just look into the module. It provides a simple function, 108 called jsmin which takes the script as a string and returns the minified 109 script as a string. 110 111 The module additionally provides a "streamy" interface similar to the one 112 jsmin.c provides: 113 114 $ python -mrjsmin <script >minified 115 116 It takes two options: 117 118 -b Keep bang-comments (Comments starting with an exclamation mark) 119 -p Force using the python implementation (not the C implementation) 120 121 The latest documentation is also available online at 122 <http://opensource.perlig.de/rjsmin/>. 123 124 125 BUGS 126 ---- 127 128 No bugs, of course. ;-) 129 But if you've found one or have an idea how to improve rjsmin, feel free 130 to send a pull request on `github <https://github.com/ndparker/rjsmin>`_ 131 or send a mail to <rjsmin-bugs (a] perlig.de>. 132 133 134 AUTHOR INFORMATION 135 ------------------ 136 137 Andr "nd" Malo <nd (a] perlig.de> 138 GPG: 0x8103A37E 139 140 141 If God intended people to be naked, they would be born that way. 142 -- Oscar Wilde 143