ミニファイヤは、これで開始するとメソッドやプロパティを置き換えないため、プロトタイプの JavaScript ではそれほどうまく機能しないことに気付きました。例えば:
// unoptimized 182 bytes
myClass.prototype.myFunction = function(){
this.myElementDom.style.backgroundColor='#000';
this.myElementDom.style.color='#FFF';
this.myElementDom.style.borderColor='#DDD';
}
// 168 bytes = 92% of unoptimized, YUI compressed
myClass.prototype.myFunction=function(){this.myElementDom.style.backgroundColor="#000";this.myElementDom.style.color="#FFF";this.myElementDom.style.borderColor="#DDD"};
// optimized 214 bytes
// set a replaceable local scope variable and reduce 2 variable
// lookups at the same time
// file-size in the development version doesn't matter, so we can even increase it
// to preserve readability
myClass.prototype.myFunction = function(){
var myElementDomStyle = this.myElementDom.style
myElementDomStyle.backgroundColor='#000';
myElementDomStyle.color='#FFF';
myElementDomStyle.borderColor='#DDD';
}
// 132 bytes = 72.53% of unoptimized, YUI compressed
myClass.prototype.myFunction=function(){var a=this.myElementDom.style;a.backgroundColor="#000";a.color="#FFF";a.borderColor="#DDD"};
万歳、19.47% 節約されました... ではありません ...gzip を有効にしてスクリプトを公開すると、最適化されていない YUI 圧縮バージョンは 130 バイト (= 最適化されていない場合の 71.42%) でロードされ、最適化された YUI 圧縮バージョンよりも明らかに節約されます。 134 バイト (= 最適化されていない場合の 73.63%)... 圧縮のしくみを考えれば明らかかもしれませんが、どうすればよいのでしょうか? そもそもこのマイクロ最適化と小さな圧縮を行うと、gzip を使用してより大きなファイルサイズを正当化できます...このような最適化により、コードの読みやすさと保守性を簡単に低下させることができるためです。
http://refresh-sf.com/yui/によるすべての情報