JS 压缩工具
Compress JavaScript instantly. Removes whitespace, comments, and optimizes variable names. Processed 100% in your browser — your code stays private.
JavaScrip语言输入
压缩后的输出
100% 私密
所有处理均通过 Terser.js 在您的浏览器中进行。您的代码绝不会被发送到任何服务器。
ES2020+ 支持
Terser支持现代JavaScript ,包括箭头函数、async/await、classes和模板文本。
加快页面加载速度
压缩JS可将文件大小减少30–70% ,提高交互时间和核心Web Vitals分数。
什么是 JavaScript 压缩?
JavaScript压缩是从源代码中删除所有不必要的字符而不更改其功能的过程。这包括空格、换行符、注释和长变量名称—这些名称被替换为较短的等效名称。结果是一个更小的文件,下载和解析速度更快,但功能与原始文件相同。
This tool uses Terser — the industry-standard JavaScript minifier and the engine behind Webpack, Vite, and esbuild. Terser performs both minification (removing whitespace and comments) and mangling (renaming variables to shorter names like a, b, c), achieving reductions of 30–70% depending on code style. It fully supports ES2020+ syntax including async/await, optional chaining, and nullish coalescing.
压缩JavaScript可直接改善Core Web Vitals。较小的JS捆绑包可减少交互时间(TTI)和总阻塞时间(TBT) ,这是Google在其Lighthouse审计中衡量的两个指标,并用作排名信号。Google的PageSpeed Insights会将未缩小的JavaScript标记为“消除渲染阻止资源”或“缩小JavaScript”机会。
何时压缩 JavaScript
在以下情况下压缩 JS:
- ✓ 部署到生产—始终提供压缩的JS
- ✓ 您的PageSpeed Insights分数显示“压缩JavaScript”
- ✓ 处理未预先缩小的第三方脚本
- ✓ 为使用慢速连接的移动端用户减少负载
- ✓ 缩短交互时间( TTI )和总阻塞时间
- ✓ 在部署之前组合多个小型脚本
典型的尺寸减小:
- • Well-commented library: 50–70% reduction
- • Typical application code: 30–50% reduction
- • Already compressed or generated code: 10–20% reduction
- • 顶部额外的gzip压缩:进一步60–80%
为了获得最大效果,请先压缩,然后从Web服务器使用gzip或Brotli压缩。
常见问题
这个工具对您有帮助吗?
感谢您的反馈!
反馈发送失败,请重试。