Improve load times, save costs and find potential JavaScript problems with this useful and easy to use command line tool!
This tool reduces the size of your JavaScript using a variety of methods including:
✂️ Comments are useful when working on a file but not needed in the published version.
✂️ As above, useful for debugging when making programs but not needed in published applications.
✂️ To save even more bytes!
💥 Multi-line declarations, where possible, are converted to a single line to save more bytes.
🎨 Changing a colours name from a 6 characters to 3 characters (e.g. #00ff00 to #0f0) saves a few more bytes!
As well as making the file smaller, the tool also checks for possible problems and suggests improvements:
✔️ Not a common problem, but it checks for multiple functions with the same name.
✔️ Maybe subjective but tells you if you are not using 'strict mode' or if you are still using 'var' when it should be 'let / const'. Useful when updating old files.
As it was made more for my use than the public it is very simple to use, all you need to do is give it a file and it will produce a compressed version called 'compiled.js', e.g.:
>jsopt trak.js
JavaScript Optimiser v0.# Go (##/##/2026) by ssjx (https://ssjx.co.uk)
======================================================================
Input: trak.js
Output: compiled.js
JavaScript Health Check
-----------------------
* Missing 'use strict' at the top of file.
* 'var' found, consider using 'let' or 'const' instead.
* Duplicate function(s):
loadImages
The errors above were created to make sure the tool worked! The test file (trak.js) size went from 59KB to 38KB which is nearly a third off the size!
To create a differently named output file, just add that onto the end of the command e.g.:
>jsopt trak.js newfile.js JavaScript Optimiser v0.# Go (##/##/2026) by ssjx (https://ssjx.co.uk) ====================================================================== Input: trak.js Output: newfile.js JavaScript Health Check ----------------------- No problems found!
⚠️ Please note that this tool is not perfect, and it will likely fail on complex or convoluted JavaScript files. As I use it more and more on my own work, it may get better over time so check back for updates!