This script 'crunches' - removes syntactically superfluous formatting whitespace - from CSS, HTML, JS, and XML source files.
It works on a line by line basis for easier comparison with the original, using programs such as WinDiff. Depending on the formatting of the original, it reduces file size by up to about a third, that is to 60-70% of the original.
The input type setting ensures that the input is crunched by the appropriate method, this includes inline <style> and <script> sections within HTML. In all types, quoted strings are never crunched.
The crunching of comments is determined by further settings, individually alterable for each type of input. By default only 'forced' comments will be left in any type of code, but all or no comments can be included by making the appropriate choices. 'Forced' comments are:
A further option overrides the default end-of-line character(s). By default, whatever the browser supplies as \n will be used. This is likely to be a LF \x0A on Linux or Unix machines and a CRLF \x0D\x0A pair on Windows machines, and a CR \x0D on Macs, but the setting can be used to force whichever is preferred.
By default a comment,"Crunched by: <This URL>, <Date>", will be added to the output. This can be edited, or omitted altogether by blanking it.
To use this online version, paste your code into the input, set the parameters, click Submit, and copy the resulting crunched output to a different file. To download the console script to your PC, <Right-Click> Crunch.js and choose Save As.
Note: In some browsers, this online version will not handle unicode scripts correctly.
Updated | Description |
---|---|
19/02/2017 | v1.3 - Added choice of Mac line ends, now processes correctly PHP & SSI tags & files. |
19/10/2010 | v1.2 - Bugfixes in JavaScript compression - regular expression literals and some obscure coding sequences are now handled properly. It's not recommended, but if you absolutely must have this version 1.2 rather than the current version, <Right-Click> Crunch1-2.js and choose Save As. |
13/06/2010 | v1.1 - Safer Array for() loops if the Array.prototype is altered. |
24/05/2010 | Created v1. |