Lua Minifier
Strip comments and whitespace from Lua, safely.
About the Lua Minifier
What is a Lua minifier?
Minifying Lua means removing everything the interpreter does not need, which means comments, indentation, and the line breaks between statements. The result behaves identically but takes up less space, which matters when a script is downloaded over the network, embedded in a game asset, or pushed to a device with limited storage.
This minifier reads your code as a stream of tokens rather than running find-and-replace over the text, which is what makes it safe. Whitespace inside a string is left alone. A -- that appears inside a string is not mistaken for a comment. Two tokens are only ever pushed together when that cannot change their meaning, so a - -b keeps its space and never collapses into the comment marker --.
There is one deliberate limit. It does not rename your local variables. Renaming can squeeze out more bytes, but in Lua it is genuinely risky, because a name can be reached through _ENV, a global lookup, or a string passed to load in ways no minifier can see. This tool prioritises code that still works over the last few percent.
How to Use This Tool
- Paste your Lua. Drop it into the left pane or use Open file to load a
.luafile. It minifies as you type. - Watch the size stats. The counter above the output shows the before and after size and how much you saved.
- Check the badge. Green means the code parsed cleanly. Red names the problem and its line, and no output is produced.
- Ship it. Copy the result or download it as a
.min.luafile. Switch Mode to Beautify to expand it again.
Common Use Cases
- Shrinking game scripts: Roblox, Garry's Mod, and Love2D projects ship a lot of Lua, and comments add up across many files.
- Embedded and IoT targets: NodeMCU and similar boards run Lua with very little room to spare.
- Bundling addons for download: A smaller archive is a faster install for the people using it.
- Stripping comments before sharing: Useful when internal notes should not travel with the code.
- Measuring real size: See what a script actually costs once formatting is removed.
Need the opposite? The Lua Formatter expands minified Lua back into readable code. See also the JavaScript Minifier and CSS Minifier, or the rest of our free developer tools.
Frequently Asked Questions
Will minifying break my script?
It should not. Only whitespace and comments are removed, and every remaining token comes out in the same order it went in. The one case that needs care is a statement starting with an opening parenthesis on a new line, which Lua would otherwise read as a call on the previous line, and the minifier inserts a semicolon there to keep the original meaning.
Does it rename variables to save more space?
No, and that is deliberate. Renaming locals can save more bytes, but a name in Lua can be reached through _ENV, a global lookup, or code built at runtime and passed to load, none of which a minifier can see. Removing whitespace and comments is the part that is always safe.
How much smaller will my file get?
It depends almost entirely on how heavily commented the source is. Well-documented code with generous indentation often drops by 30 to 50 percent, while code that is already compact may only lose a few percent. The stats above the output show the exact figure for your file.
Are comments always removed?
Yes, including long comments written as --[[ ... ]] at any bracket level. If the file begins with a #! shebang line that is kept, since Lua treats it specially and removing it would stop the script running directly.
Can I get my original formatting back?
You can get readable formatting back, but not your exact original. Comments are gone for good once removed, so keep the source. Switching Mode to Beautify, or using the Lua Formatter, will re-indent minified code into something readable again.
Is my code uploaded anywhere?
No. The tokenizer and minifier are plain JavaScript running in your browser, so your code never leaves the machine and the tool keeps working offline once the page has loaded.