JavaScriptStrip
Home and Help
miniAPPolis.com Home | JavaScriptStrip Home Page | Feedback to Developer
- Purpose
- JavaScriptStrip is a fast, compact (31k) Windows 32 Utility for JavaScript to make
scripts loaded with the tag <script type
="text/JavaScript" src="MyFile.js"> more compact
by removing comments, unnecessary blanks, and line feeds from script source code. It also replaces variable
names with randomly generated "aliases". The compaction afforded by stripping "white space"
and scrunching variable names can result in 25%-40% file size reduction.
In addition, with all the code on a
single line and with meaningless variable names, your code becomes much less accessible to potential
imitators.
- Caveats
-
- All variables to be renamed must be declared in a var statement
or else appear as arguments in a function declaration.
- All statements must end in ; and control structures must be
properly delimited with { }.
- Variable names may not be identical to words appearing in string literals,
regular expressions or names of document elements referenced in script.
- To avoid being changed, string literals may not contain
// /* */ or consecutive blanks. Instead, create such strings by concatenation:
"http:/" + "/miniappolis.com"
JavaScriptStrip uses regular expression pattern matching
to find and replace occurrences of variable names with aliases. Thus it replaces any occurrence of the
variable name string within word boundaries. Similarly, it is not sensitive to whether // /* */ or multiple spaces
occur within quotation marks. These limitations dictated by performance considerations cause no problems
if you are aware if them. For example, avoid calling a variable HTML if you want to use the string
HTML somewhere in a literal or regular expression; sHTML is a good alternative name.
- Use
- In Windows Explorer, drag and drop the icon of the file(s)
to be stripped onto JavaScriptStrip's icon. Alternatively you can
copy a shortcut to JavaScriptStrip.exe into the C:\Windows\SendTo folder. Then when you select the files to be stripped,
right-click in the Explorer window and choose "SendTo
JavaScriptStrip." Advantage: this approach makes JavaScriptStrip available
from any folder. Double-click on the program's icon to see a help
and copyright message.
- Output
- MyFile.js is the stripped file.
- MyFile.bak is a backup of your original file. To
prevent your original file from being overwritten by the output, give it an
extension other than .js, e.g. MyFile.txt.
- MyFile.varkey.txt lists the original variable names and
functions and shows new alias names for the variables.
- Options
- When you drop or send one or more filenames to JavaScriptStrip, a
dialog box prompts you for options. Enter the letters of any options you want and click "OK", or
else click
"Cancel" to accept the default values. The option letters
may be entered in UPPER or lower case. Any separators you might
enter (space, comma
etc.) are ignored. The options are:
- F : put each function on a separate line (default: strip all
carriage returns and line feeds). Useful for debugging when error
messages indicate in which line an error has occurred.
- L : leave in carriage returns and line feeds (default:
strip all out). Useful for proofreading.
- R : repeatable random variable alias names (default: each time
the program is run variables are given different aliases; with this option the
variables receive the same nonsense name each time the program is run). Useful for
debugging and proofreading.
- Sdd, where d stands for any digit 1-9 : specify the minimum and maximum length of alias names (default:
minimum 1, maximum 6 characters). Useful to optimize either
compactness (small numbers) or obfuscation (large numbers). For example,
specifying the option S47 would make all
variable names 4-7 characters long. Note: since both UPPER- and lower-case letters are
used for randomly-generated aliases, even names as short as 1-2 characters permit large numbers of unique
variable names, e.g. 52 + 522 = 2756 unique names.
- V : retain original variable names (default: assign all variables
random alias names). Useful for debugging, and for only compacting the
list, without variable name aliasing.
- Pre-run / Debugging Checklist
- Script has already been debugged and thoroughly tested.
- Script
filename does not end in .js
- All variables are declared in var
statements or appear as function arguments.
- All statements are
terminated with ;
- All structures (function, if
... else, for, switch etc.) are properly
enclosed in { }.
- No variable names are identical to words
that occur in string literals or regular expressions, or to names of
form elements referenced in the script.
- No string literals contain
any of the sequences // /* */ or two spaces.
- Download and Installation
- Click either
this link for a zip file with the application and this help screen (19k), or
else this
link for the uncompressed JavaScriptStrip.exe (25k) file. Save JavaScriptStrip.exe
to a folder of your choice. In Windows Explorer, right-click on on JavaScriptStrip.exe's icon
to create a shortcut to this application. Copy this link to the C:\Windows\SendTo folder to make
it available from any folder. To uninstall, delete JavaScriptStrip.exe.
Close Help Window | JavaScriptStrip Home Page | Feedback to Developer
Freeware ©2001 by William H. Fletcher, fletcher@miniappolis.com
All rights reserved, including those of (re)distribution. Ver. 13 March 2001.
Download and details: http://miniappolis.com/utilities/JavaScriptStrip.html