JS/CSS的压缩已经不是什么新鲜话题了,自打YSlow推出后,这方面的优化话题是铺天盖地啊;不过当时作为后知后觉的我,甚至都没法完整地写出一份漂亮的JS/CSS的代码,何尝会去注意呢?!
时至今日,我仍然没法独立完整地写出一份专业的代码,但对能够压缩这类代码也有了应有的兴趣和需要,动手实现刻不容缓!
百度了很多这方面的教程,尝试了很多解决方案,可谓几经周折方才成功;喜悦之余,分享于此。
本秘籍宗旨只为实现在右键集成YUI Compressor和Editplus集成YUI Compressor。
1、关于YUI Compressor
YUI Compressor – The Yahoo! JavaScript and CSS Compressor
The YUI Compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as ‘eval’ or ‘with’ (although the compression is not optimal is those cases) Compared to jsmin, the average savings is around 20%.
The YUI Compressor is also able to safely compress CSS files. The decision on which compressor is being used is made on the file extension (js or css)
对于大量使用JavaScript和CSS的AJAX应用来说,如果JavaScript和CSS大小很大,则传输到客户端的时间会很久,网站性能不佳。而压缩JavaScript和CSS是自然的事情(其中YUI Compressor的压缩率大约为20%);
大致就是这么个意思,其实我们只要关注YUI Compressor能实现什么就行。
Continue reading 利用YUI Compressor压缩JS/CSS之终极秘籍