Lua Minifier

Cut comments and whitespace out of Lua without disturbing a single string literal.

Lua
Minified Lua
Runs locally in your browser

About the Lua Minifier

Lua ships as source, so the file you deploy is the file the interpreter reads. On a Roblox place, a Love2D build, an OpenResty config or a Neovim plugin, comments and indentation are pure overhead once the code is stable. This minifier tokenises the script properly and rebuilds it from the tokens, which means it can tell a comment from a hyphen inside a string and never damages the second one.

Every string form is understood: single and double quoted strings with escapes, and long bracket strings from [[ ]] through [==[ ]==] at any level. Long comments in the matching --[[ ]] and --[=[ ]=] forms are recognised too, which is where naive line based strippers usually fall apart. Numbers keep their hexadecimal, decimal and exponent forms exactly as written.

Spaces are reinserted only where Lua needs them. Two adjacent words such as local x or end return keep their separator; a number followed by concatenation gets a space so 1 ..x is never read as a malformed number; and a run of hyphens can never accidentally form a comment marker. One line output is the smallest, while keep line structure preserves the original line breaks so a runtime stack trace still points near the right place. Nothing is renamed, so upvalues, globals and any name reached through _G keep working. Compare the saving with the JavaScript Minifier if the same logic exists in both languages.

How to use

  1. Paste your Lua, or drop a .lua file on the left pane.
  2. Choose One line for the smallest file, or keep the line structure for readable stack traces.
  3. Check the saving in the status bar, then download the minified script.

Common questions

Does it rename local variables?
No. Renaming would break anything reached through _G, setfenv, load or a debug hook, so only comments and whitespace are removed.
Are long strings and long comments handled?
Yes, at any bracket level. Long strings are copied through byte for byte and long comments are removed as single units.
Why is there still a space in some places?
Lua needs a separator between two words, between a number and a following dot, and anywhere two characters would otherwise merge into a comment or an operator. Those spaces are required for the code to still parse.
What happens if a string is never closed?
The minifier stops and reports the line and column where the string opened, rather than producing a file that will not load.