Lua Minifier

Strip comments and whitespace from Lua scripts.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

Lua Minifier – Compress Lua Scripts

The Lua minifier removes comments and every unnecessary space and line break from Lua code. Smaller scripts load faster in constrained environments — embedded devices, game mods with size limits, Redis EVAL calls, or scripts sent over the network.

What it removes

  • Line comments (-- ...) and block comments (--[[ ... ]], --[==[ ... ]==]).
  • Indentation, line breaks, and spaces that are not needed to separate tokens.

What it keeps

  • Strings in single and double quotes, including escape sequences.
  • Long strings like [[ ... ]] and [==[ ... ]==], byte for byte.
  • Identifiers – names are not shortened, so global functions, table fields, and API callbacks keep working.
  • The shebang line (#!/usr/bin/lua) if you want it.

Safe token joining

Lua is mostly whitespace-insensitive, but a few combinations need care. The minifier keeps a space where removing it would change the meaning: between two names or keywords (local x), between operators that would merge (- -x would otherwise become a comment), after a number before .. (1 .. 2 must not become the malformed number 1..2), and between [ and a long-string bracket.

Size savings

The chips below the output show the original size, minified size, and percentage saved. Heavily commented scripts often shrink by half.

Minify vs. obfuscate

This tool minifies; it does not obfuscate. Code remains readable after re-formatting, and variable names are unchanged. That keeps it safe for code that is called by name from a host application.

Make minified Lua readable again with the Lua Beautifier, or minify other languages with the JS Minifier and SQL Minifier.

Frequently Asked Questions

No. Renaming local variables saves more bytes but can break code that is accessed by name from C or another script. The minifier only removes comments and whitespace.

Lua 5.1 through 5.4 and LuaJIT syntax, including integer division //, bitwise operators, goto labels, and long brackets with any level.

Yes. Minified code is on fewer lines, so runtime errors point to different lines. Keep the original source for debugging.