Lua Minifier
Strip comments and extra whitespace from Lua at the lexer level — long strings and quoted strings preserved exactly.
Lua minifying fails in a characteristic way when it is done with search-and-replace: a “--” inside a string is not a comment, a “--” that opens a long comment --[[ … ]] ends at the matching bracket and not at the end of the line, and gluing tokens together carelessly creates new tokens (a minus next to a minus becomes a comment; a number next to .. becomes a malformed numeral). This minifier therefore works the way Lua itself reads the code — as a lexer. It walks the source token by token, recognising quoted strings with their escapes, long-bracket strings at any level ([==[ … ]==] included), line comments, long comments, numbers, names and operators, then re-emits only the tokens, inserting a space only where two tokens would otherwise merge.
Minifying runs in this browser only — your code is never uploaded, stored or put into a link. The minifier works at the lexer level: quoted strings and long-bracket strings such as [[...]] are copied character for character, so a -- inside a string is never mistaken for a comment.
Quick answers
How do I minify Lua code?
Lex the source into tokens, drop comment tokens, and re-join the rest with a space only where tokens would merge. Strings — quoted and [[long-bracket]] — are single tokens, so their contents survive exactly: a -- inside a string is never treated as a comment.
Watch the joins: a number before .. and a minus before a minus both need their separating space, or the minified code lexes differently from the original.
Why do simple Lua minifiers break code?
Because they edit text instead of tokens: they cut strings at a -- that was string content, end long comments at the first ]] instead of the matching bracket level, or glue tokens into new ones (two minuses become a comment). A lexer-level minifier avoids all three by construction.
Renaming identifiers is the other trap — it needs full scope analysis, so this tool does not rename at all.
How to use
- Paste your Lua into the top box — a game script, an embedded config, a module.
- Read the minified result below and the size line: characters before and after.
- Spot-check any long string in the result: its contents, including newlines and any -- inside it, are copied exactly.
- Copy the minified code out. Identifiers are not renamed, so the output stays debuggable — keep the original as your source regardless.
About this tool
The worked example to hold it to: a source whose long string reads [[keep -- me]] keeps those exact characters in the output — the -- inside a long string is text, not a comment — while a real -- comment on the same line vanishes. Leveled long comments (--[==[ … ]==]) are skipped to their true closing bracket, even when a plain ]] appears inside them. What this tool does not do is rename locals or obfuscate: renaming requires full scope analysis, and a minifier that guesses at scope eventually renames something it should not. The output is your code with the air let out — same names, same strings, fewer bytes.
Frequently asked questions
Will it break code that has -- inside a string?
No — that case is the reason the tool is a lexer rather than a text filter. Quoted strings and long-bracket strings are recognised as single tokens before comments are considered, so local s = "a -- b" and local s = [[a -- b]] both keep their contents character for character while genuine comments around them are removed.
How are long comments handled?
Both forms are recognised: -- to the end of the line, and long comments --[[ … ]] including leveled brackets --[==[ … ]==]. A leveled long comment is skipped to its matching leveled close, so a ]] appearing inside it does not end it early — the classic way naive minifiers corrupt code.
Does it rename variables to shorten the code further?
No, deliberately. Safe renaming needs complete scope analysis (globals, upvalues, _ENV, dynamic access); a front-end minifier that approximates it will eventually rename something load-bearing. This tool removes comments and whitespace only — expect a solid saving on commented code, with output you can still read and diff.
Which Lua versions does it cover?
The lexer covers the shared core of Lua 5.1 through 5.4: long strings and comments at any bracket level, hex and exponent numerals, the //, <<, >> and :: operators from 5.3+, labels and goto. Luau-only syntax (type annotations, compound assignment) is not covered — see the note that a Luau formatter/analyser is a different, much larger tool, which this site does not claim to offer.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.