Minify JavaScript without uploading your source
Minifying strips whitespace and shortens local names so a script downloads faster. It is a size optimisation and not a secrecy one, because anything the code needs at runtime is still readable in the output.
At a glance
- Tools
- /tools/javascript-minifier, and /tools/css-minifier for stylesheets
- Removed
- Whitespace, comments and long local names
- Kept
- Every string, URL and key the code needs in order to run
- What it is not
- Encryption, obfuscation or protection
- Usual source
- Private application code, often under a client agreement
- After minifying
- Test the output, then keep the readable source
In detail
The file being minified is somebody's product, and frequently somebody else's product under an agreement that says where the source may and may not go. Working source is candid in a way shipped source is not: comments name people, ticket numbers and the reason a workaround exists, and internal hostnames sit in plain strings waiting to be read. That is an argument for the minifier not being a network service, quite apart from how careful the code is.
The limit worth stating is that minified code is still code. Strings survive because the program needs them, so an endpoint URL is just as visible after minification as before, and a key committed into a front-end file is exactly as exposed. Shortening variable names makes reading less pleasant; it does not make anything secret.
Test what comes out. Code that depends on how it was written, on a function's own name for example, can behave differently once names are shortened, and the failure usually appears somewhere unrelated. Minify as a build step against a readable source you keep, never as an edit to the only copy you have.
Verify the source stayed local by pasting it in with the network disconnected. Text in, shorter text out, no server involved. For code you are contractually not allowed to disclose, that is the difference between a routine optimisation and a breach nobody would ever have noticed.
Things that catch people out
- Minification is not obfuscation and neither one is protection. Anything shipped to a browser is readable by whoever receives it.
- A key or token in front-end source is public the moment the page loads. Move it behind a service you control and rotate the exposed one.
- Test the minified output before shipping it. Code that relies on function names or on source text can break when names are shortened.
Try it: Hash Generator
The file hasher is on every page here because it takes any file at all and proves the point: disconnect from the network, drop a file in, and it still returns a checksum you can compare against a published one.
Hash Generator
LOCAL · Browser-OnlyGenerate MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, Keccak-256, CRC32, and HMAC hashes from text or files
MD5 is cryptographically broken and should not be used for security purposes. Use SHA-256 or SHA-512 instead.
Related Working without uploading
All working without uploading →Optimise an SVG without uploading it
Clean up SVG markup in your browser. What an exported SVG carries beyond the drawing, and why that is a disclosure risk, not just weight.
Format and validate JSON without uploading it
Tidy and check JSON in your browser. The JSON people paste into a formatter is usually a live API response full of real records.
Turn HTML into a PDF without uploading your markup
Render HTML to PDF in your browser. Your markup is not uploaded, though remote images and fonts it references are still fetched normally.
Hash a file without uploading it
Checksum a file in your browser with SHA-256 and eight other algorithms. A hash proves the bytes match; it keeps nothing secret.
Decode a JWT without sending it to a website
Read and verify a token in your browser. A JWT is a live credential: pasting one into a hosted decoder hands over a working session.
Check a .env file without uploading your secrets
Find duplicate keys, mask values and generate a .env.example locally. A .env is nothing but credentials, so uploading one means rotating them.
Tools for this
- JavaScript Minifier Free online javascript minifier - minify JavaScript code to reduce file size and improve load times
- CSS Minifier Free online CSS minifier - minify your CSS code to reduce file size and improve load times
- Code Formatter Free online code formatter - beautify and format JavaScript, CSS, HTML, and more