patchwork/jsqueeze
最新稳定版本:v2.0.5
Composer 安装命令:
composer require patchwork/jsqueeze
包简介
Efficient JavaScript minification in PHP
README 文档
README
JSqueeze shrinks / compresses / minifies / mangles Javascript code.
It's a single PHP class that has been developed, maintained and thoroughly tested since 2003 on major JavaScript frameworks (e.g. jQuery).
JSqueeze operates on any parse error free JavaScript code, even when semi-colons are missing.
In term of compression ratio, it compares to YUI Compressor and UglifyJS.
Installation
Through composer:
{ "require": { "patchwork/jsqueeze": "~2.0" } }
Usage
use Patchwork\JSqueeze; $jz = new JSqueeze(); $minifiedJs = $jz->squeeze( $fatJs, true, // $singleLine true, // $keepImportantComments false // $specialVarRx );
Features
- Removes comments and white spaces.
- Renames every local vars, typically to a single character.
- Keep Microsoft's conditional comments.
- In order to maximise later HTTP compression (deflate, gzip), new variables names are choosen by considering closures, variables' frequency and characters' frequency.
- Can rename also global vars, methods and properties, but only if they are marked
special by some naming convention. Use JSqueeze::SPECIAL_VAR_PACKER to rename vars
whose name begins with one or more
$or with a single_. - Renames also local/global vars found in strings, but only if they are marked special.
- If you use
with/evalthen be careful.
Bonus
- Replaces
false/trueby!1/!0 - Replaces
new Array/Objectby[]/{} - Merges consecutive
vardeclarations with commas - Merges consecutive concatened strings
- Can replace optional semi-colons by line feeds, thus facilitating output debugging.
- Keep important comments marked with
/*!... - Treats three semi-colons
;;;like single-line comments. - Fix special catch scope across browsers
- Work around buggy-handling of named function expressions in IE<=8
To do?
- foo['bar'] => foo.bar
- {'foo':'bar'} => {foo:'bar'}
- Dead code removal (never used function)
- Munge primitives: var WINDOW=window, etc.
License
This library is free software; you can redistribute it and/or modify it under the terms of the (at your option): Apache License v2.0 (see provided LICENCE.ASL20 file), or GNU General Public License v2.0 (see provided LICENCE.GPLv2 file).
patchwork/jsqueeze 适用场景与选型建议
patchwork/jsqueeze 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.77M 次下载、GitHub Stars 达 152, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「compression」 「minification」 「javascript」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patchwork/jsqueeze 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patchwork/jsqueeze 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patchwork/jsqueeze 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
统计信息
- 总下载量: 5.77M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 158
- 点击次数: 36
- 依赖项目数: 103
- 推荐数: 28
其他信息
- 授权协议: (Apache-2.0 or GPL-2.0) 693d64850eab2ce6a7c8f7cf547e1ab46e69d542
- 更新时间: 2026-01-04