ajaxmin(js,css压缩工具)

Microsoft Ajax Minifier使用:

使用方法一:

开始-->Microsoft Ajax Minifier-->Microsoft Ajax Minifier Command Prompt,弹窗命令窗口,输入相关命令即可。

使用方法二:

找到安装目录(C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier),找到AjaxMinCommandPrompt.bat,双击它就会弹窗命令窗口,输入相关命令即可。

(用ajaxmin或ajaxmin.exe都行,都是调安装目录下的AjaxMin.exe程序)

  1. 压缩并覆盖源文件
    ajaxmin inputfile.js
  2. 压缩到新文件(若文件已经存在会报错)
    ajaxmin inputfile.js -out outputfile.js
    ajaxmin.exe inputfile.js -out outputfile.js
  3. 用参数 -clobber 覆盖目标文件时不报错
    ajaxmin inputfile.js –out outputfile.js -clobber
    ajaxmin.exe inputfile.js –out outputfile.js -clobber
  4. 缺省状态下,本工具将重命名所有的本地变量和函数,若不想更改,可使用-rename:none参数
    ajaxmin -rename:none inputfile.js -out outputfile.js
    ajaxmin.exe -rename:none inputfile.js -out outputfile.js
  5. 偶尔在调试已经压缩过的js文件或则需要分析已有的压缩过的js文件时,可以使用这个工具进行还原,这样规范化以后由于格式整齐,就更好分析。
    ajaxmin -pretty demo.min.js -clobber -o demo.js
    ajaxmin.exe -pretty demo.min.js -clobber -o demo.js

压缩原理


  • 去掉不必要的空格
  • 去掉备注(忽略标注了"important"的备注)
  • 去除不必要的分号
  • Remove curly-braces around most single-statement blocks.
  • 重命名本地变量和函数
  • Determine best string delimiters (single- or double-quotes) based on which option will generate the fewer escaped characters within the string.
  • 合并多行连续的变量声明
  • 删除构造函数中的空参数
  • Remove unreferenced names for named function expressions.
  • 删除无引用的本地函数
  • 删除无法到达的代码
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容