• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="ascii"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3          "DTD/xhtml1-transitional.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5<head>
6  <title>rjsmin</title>
7  <link rel="stylesheet" href="epydoc.css" type="text/css" />
8  <script type="text/javascript" src="epydoc.js"></script>
9</head>
10
11<body bgcolor="white" text="black" link="blue" vlink="#204080"
12      alink="#204080">
13<!-- ==================== NAVIGATION BAR ==================== -->
14<table class="navbar" border="0" width="100%" cellpadding="0"
15       bgcolor="#a0c0ff" cellspacing="0">
16  <tr valign="middle">
17  <!-- Home link -->
18      <th bgcolor="#70b0f0" class="navbar-select"
19          >&nbsp;&nbsp;&nbsp;Home&nbsp;&nbsp;&nbsp;</th>
20
21  <!-- Tree link -->
22      <th>&nbsp;&nbsp;&nbsp;<a
23        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
24
25  <!-- Index link -->
26      <th>&nbsp;&nbsp;&nbsp;<a
27        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
28
29  <!-- Help link -->
30      <th>&nbsp;&nbsp;&nbsp;<a
31        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
32
33  <!-- Project homepage -->
34      <th class="navbar" align="right" width="100%">
35        <table border="0" cellpadding="0" cellspacing="0">
36          <tr><th class="navbar" align="center"
37            ><a href="http://opensource.perlig.de/rjsmin/" target="_top">Visit rjsmin Online</a></th>
38          </tr></table></th>
39  </tr>
40</table>
41<table width="100%" cellpadding="0" cellspacing="0">
42  <tr valign="top">
43    <td width="100%">
44      <span class="breadcrumbs">
45        Module&nbsp;rjsmin
46      </span>
47    </td>
48    <td>
49      <table cellpadding="0" cellspacing="0">
50        <!-- hide/show private -->
51      </table>
52    </td>
53  </tr>
54</table>
55<!-- ==================== MODULE DESCRIPTION ==================== -->
56<h1 class="epydoc">Module rjsmin</h1><p class="nomargin-top"><span class="codelink"><a href="rjsmin-pysrc.html">source&nbsp;code</a></span></p>
57<p>rJSmin is a javascript minifier written in python.</p>
58<p>The minifier is based on the semantics of <a class="rst-reference external" href="http://www.crockford.com/javascript/jsmin.c" target="_top">jsmin.c by Douglas Crockford</a>.</p>
59<p>The module is a re-implementation aiming for speed, so it can be used at
60runtime (rather than during a preprocessing step). Usually it produces the
61same results as the original <tt class="rst-docutils literal">jsmin.c</tt>. It differs in the following ways:</p>
62<ul class="rst-simple">
63<li>there is no error detection: unterminated string, regex and comment
64literals are treated as regular javascript code and minified as such.</li>
65<li>Control characters inside string and regex literals are left untouched; they
66are not converted to spaces (nor to n)</li>
67<li>Newline characters are not allowed inside string and regex literals, except
68for line continuations in string literals (ECMA-5).</li>
69<li>&quot;return /regex/&quot; is recognized correctly.</li>
70<li>Line terminators after regex literals are handled more sensibly</li>
71<li>&quot;+ +&quot; and &quot;- -&quot; sequences are not collapsed to '++' or '--'</li>
72<li>Newlines before ! operators are removed more sensibly</li>
73<li>Comments starting with an exclamation mark (<tt class="rst-docutils literal">!</tt>) can be kept optionally</li>
74<li>rJSmin does not handle streams, but only complete strings. (However, the
75module provides a &quot;streamy&quot; interface).</li>
76</ul>
77<p>Since most parts of the logic are handled by the regex engine it's way faster
78than the original python port of <tt class="rst-docutils literal">jsmin.c</tt> by Baruch Even. The speed factor
79varies between about 6 and 55 depending on input and python version (it gets
80faster the more compressed the input already is). Compared to the
81speed-refactored python port by Dave St.Germain the performance gain is less
82dramatic but still between 3 and 50 (for huge inputs). See the docs/BENCHMARKS
83file for details.</p>
84<p>rjsmin.c is a reimplementation of rjsmin.py in C and speeds it up even more.</p>
85<p>Both python 2 and python 3 are supported.</p>
86
87<hr />
88<div class="fields">      <p><strong>Copyright:</strong>
89        Copyright 2011 - 2015
90Andr&#233; Malo or his licensors, as applicable
91      </p>
92      <p><strong>License:</strong>
93        <p>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
94you may not use this file except in compliance with the License.
95You may obtain a copy of the License at</p>
96<blockquote>
97<a class="rst-reference external" href="http://www.apache.org/licenses/LICENSE-2.0" target="_top">http://www.apache.org/licenses/LICENSE-2.0</a></blockquote>
98<p>Unless required by applicable law or agreed to in writing, software
99distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
100WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101See the License for the specific language governing permissions and
102limitations under the License.</p>
103      </p>
104      <p><strong>Version:</strong>
105        1.0.12
106      </p>
107      <p><strong>Author:</strong>
108        Andr&#233; Malo
109      </p>
110</div><!-- ==================== FUNCTIONS ==================== -->
111<a name="section-Functions"></a>
112<table class="summary" border="1" cellpadding="3"
113       cellspacing="0" width="100%" bgcolor="white">
114<tr bgcolor="#70b0f0" class="table-header">
115  <td align="left" colspan="2" class="table-header">
116    <span class="table-header">Functions</span></td>
117</tr>
118<tr>
119    <td width="15%" align="right" valign="top" class="summary">
120      <span class="summary-type"><tt class="rst-docutils literal">str</tt></span>
121    </td><td class="summary">
122      <table width="100%" cellpadding="0" cellspacing="0" border="0">
123        <tr>
124          <td><span class="summary-sig"><a href="rjsmin-module.html#jsmin" class="summary-sig-name">jsmin</a>(<span class="summary-sig-arg">script</span>,
125        <span class="summary-sig-arg">keep_bang_comments</span>=<span class="summary-sig-default">False</span>)</span><br />
126      Minify javascript based on <a class="rst-reference external" href="http://www.crockford.com/javascript/jsmin.c" target="_top">jsmin.c by Douglas Crockford</a>.</td>
127          <td align="right" valign="top">
128            <span class="codelink"><a href="rjsmin-pysrc.html#jsmin">source&nbsp;code</a></span>
129
130          </td>
131        </tr>
132      </table>
133
134    </td>
135  </tr>
136</table>
137<!-- ==================== FUNCTION DETAILS ==================== -->
138<a name="section-FunctionDetails"></a>
139<table class="details" border="1" cellpadding="3"
140       cellspacing="0" width="100%" bgcolor="white">
141<tr bgcolor="#70b0f0" class="table-header">
142  <td align="left" colspan="2" class="table-header">
143    <span class="table-header">Function Details</span></td>
144</tr>
145</table>
146<a name="jsmin"></a>
147<div>
148<table class="details" border="1" cellpadding="3"
149       cellspacing="0" width="100%" bgcolor="white">
150<tr><td>
151  <table width="100%" cellpadding="0" cellspacing="0" border="0">
152  <tr valign="top"><td>
153  <h3 class="epydoc"><span class="sig"><span class="sig-name">jsmin</span>(<span class="sig-arg">script</span>,
154        <span class="sig-arg">keep_bang_comments</span>=<span class="sig-default">False</span>)</span>
155  </h3>
156  </td><td align="right" valign="top"
157    ><span class="codelink"><a href="rjsmin-pysrc.html#jsmin">source&nbsp;code</a></span>&nbsp;
158    </td>
159  </tr></table>
160
161  <p>Minify javascript based on <a class="rst-reference external" href="http://www.crockford.com/javascript/jsmin.c" target="_top">jsmin.c by Douglas Crockford</a>.</p>
162<p>Instead of parsing the stream char by char, it uses a regular
163expression approach which minifies the whole script with one big
164substitution regex.</p>
165  <dl class="fields">
166    <dt>Parameters:</dt>
167    <dd><ul class="nomargin-top">
168        <li><strong class="pname"><code>script</code></strong> (<tt class="rst-docutils literal">str</tt>) - Script to minify</li>
169        <li><strong class="pname"><code>keep_bang_comments</code></strong> (<tt class="rst-docutils literal">bool</tt>) - Keep comments starting with an exclamation mark? (<tt class="rst-docutils literal"><span class="pre">/*!...*/</span></tt>)</li>
170    </ul></dd>
171    <dt>Returns: <tt class="rst-docutils literal">str</tt></dt>
172        <dd>Minified script</dd>
173  </dl>
174</td></tr></table>
175</div>
176<br />
177<!-- ==================== NAVIGATION BAR ==================== -->
178<table class="navbar" border="0" width="100%" cellpadding="0"
179       bgcolor="#a0c0ff" cellspacing="0">
180  <tr valign="middle">
181  <!-- Home link -->
182      <th bgcolor="#70b0f0" class="navbar-select"
183          >&nbsp;&nbsp;&nbsp;Home&nbsp;&nbsp;&nbsp;</th>
184
185  <!-- Tree link -->
186      <th>&nbsp;&nbsp;&nbsp;<a
187        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
188
189  <!-- Index link -->
190      <th>&nbsp;&nbsp;&nbsp;<a
191        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
192
193  <!-- Help link -->
194      <th>&nbsp;&nbsp;&nbsp;<a
195        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
196
197  <!-- Project homepage -->
198      <th class="navbar" align="right" width="100%">
199        <table border="0" cellpadding="0" cellspacing="0">
200          <tr><th class="navbar" align="center"
201            ><a href="http://opensource.perlig.de/rjsmin/" target="_top">Visit rjsmin Online</a></th>
202          </tr></table></th>
203  </tr>
204</table>
205
206<script type="text/javascript">
207  <!--
208  // Private objects are initially displayed (because if
209  // javascript is turned off then we want them to be
210  // visible); but by default, we want to hide them.  So hide
211  // them unless we have a cookie that says to show them.
212  checkCookie();
213  // -->
214</script>
215</body>
216</html>
217