RevealTheme logo

JavaScript压缩工具

基础的JavaScript压缩:移除注释和不必要的空白。生产环境请使用真正的压缩工具(Terser、esbuild)。

如何使用本工具

  1. 1

    Paste or type your JavaScript into the input textarea.

  2. 2

    The minified output appears instantly in the panel below as you type — there is no button to press.

  3. 3

    Check the size readout (original length, an arrow, and minified length) to see how much was removed.

  4. 4

    Select the text in the output box and copy it manually into your file.

什么是JavaScript压缩工具?

JavaScript压缩可减小代码包体积并缩短解析时间。本工具执行基础的空白和注释移除。对于生产环境的代码包,请使用Terser、esbuild或SWC:它们会进行变量名混淆和死代码消除,从而产生体积大幅缩小的输出(通常可减少60%到80%)。

常见使用场景

  • Quickly shrinking a short, comment-heavy snippet before pasting it into a tight inline <script> tag.

  • Stripping comments out of a code sample to share a compact version in a chat or gist.

  • Estimating roughly how much comment and whitespace overhead a small file carries before setting up a real build.

  • Cleaning up a hand-written configuration object or constant block that has no strings containing slashes.

  • Demonstrating to students or teammates what basic comment and whitespace removal looks like versus a real compiler.

  • Minifying a tiny utility function for a bookmarklet where pulling in a full toolchain is overkill.

常见问题

它和Terser相比如何?
Terser要激进得多:变量名混淆、死代码消除等。本工具只移除注释和空白。
这会破坏我的代码吗?
只有当你的JS存在语法问题时(在含义不明确的位置缺少分号)才会。现代JavaScript是安全的。

相关工具