CSS & JavaScript 压缩器

压缩 CSS 和 JavaScript 代码

最后更新:

关于此工具

CSS / JavaScript 压缩器去除注释、空白和冗余标记,缩减生产文件大小,提升加载和解析速度,降低 CDN 成本。构建管线通常会自动处理,但内联片段、邮件样式、不经过打包器的小脚本仍然需要快速在线压缩。

使用方法

  1. Choose CSS or JavaScript mode at the top.
  2. Paste your source into the input panel.
  3. Click Minify — the output appears on the right with the size saving in bytes and percent.
  4. Copy the minified result to embed in a <style> or <script> tag.
  5. Use the original source as the long-term editable copy and only ship the minified version.

常见用例

  • Inlining critical CSS in the <head> for faster First Contentful Paint.
  • Shrinking a Google Tag Manager custom HTML snippet to the size limit.
  • Compacting a JS one-liner you want to embed in a bookmarklet.
  • Reducing the size of email-safe CSS where every byte matters.
  • Trimming a no-bundler vanilla JS file before deploying to a static host.
  • Estimating the bundle-size impact of a snippet before adding it to a build.

常见问题

Q. Is this safe for production JavaScript?

A. For trivial scripts yes. For real applications use a battle-tested minifier like esbuild, terser, or swc inside your build pipeline so source maps and ECMAScript edge cases are handled.

Q. Why does the output break my CSS?

A. Most often a missing semicolon in the source. CSS minification assumes valid input — fix the source, then minify.

Q. Does minifying obfuscate my code?

A. Slightly — names are not changed, only whitespace is stripped. For real obfuscation use a dedicated tool, but understand it does not provide real security.

Q. Can I minify HTML the same way?

A. HTML minification needs different rules (preserved whitespace in <pre>, attribute quoting, etc.). Use a dedicated HTML minifier for that.