1# PHP JSStrip
2
3This is a PHP port of Nick Galbreath's python tool [jsstrip.py](https://code.google.com/p/jsstrip/).
4
5It was originally ported to PHP in 2006 as part of the [DokuWiki](http://www.dokuwiki.org) wiki engine. It has received several improvements over the years and is now available as a standalone library.
6
7Quoting the original description:
8
9jsstrip is a open-source library to remove whitespace and comments from a javascript file. You might want to do this to optimize size and performance, or to make a file harder to read. It typically makes 30-40% savings in file size.
10
11**WARNING**
12
13jsstrip is not a true javascript parser. It assumes you have properly delimited the 'end of line' using a ';' (semicolon).
14
15  * Yes `print 'foo'; print 'bar';`
16  * No `print 'foo' print 'bar'`
17
18You'll have to convert your code to use ';' first.
19
20ALWAYS test the stripped version before deploying to production.
21
22
23## Installation
24
25Install via composer
26
27    composer require splitbrain/php-jsstrip
28
29## Usage
30
31```php
32<?php
33
34require_once 'vendor/autoload.php';
35
36$js = file_get_contents('somefile.js'); // gather your JS here somehow
37
38$minifiedJS = (new \splitbrain\JSStrip\JSStrip())->compress($js);
39```
40
41## Skip Minification
42
43You can skip Minification for parts of your code by surrounding it by special comments:
44
45```js
46/* BEGIN NOCOMPRESS */
47const foo = 'No compression here'; // this comment will also stay
48/* END NOCOMPRESS */
49```
50