2012-04-07 18 views
1

私は、きつく絞ったjQueryスクリプトを持っています。私は、HTTPリクエストに加えて40-90kbのクライアント側ダウンロードを必要とするCDN jQueryスクリプトにリンクするのは好きではありません。jQueryから未使用の変数を削除する

新しいGoogleクロージャコンパイラは、サイズを減らすために未使用の変数をjQueryから削除するように調整できると聞いています。私はCDNリンク(グーグルのような)を使用する利点を理解していますが、私はこのコードを1ページにしか使用しないので、未使用の変数をjQueryから削除して自分でホストすることをお勧めします。

私はjQueryの1.5.2を使用して、ここで私のスクリプトだよ:

(function(a){a.fn.countDown=function(b){config={};a.extend(config,b);diffSecs=this.setCountDown(config);config.onComplete&&a.data(a(this)[0],"callback",config.onComplete);config.omitWeeks&&a.data(a(this)[0],"omitWeeks",config.omitWeeks);a("#"+a(this).attr("id")+" .digit").html('<div class="top"></div><div class="bottom"></div>');a(this).doCountDown(a(this).attr("id"),diffSecs,500);return this};a.fn.stopCountDown=function(){clearTimeout(a.data(this[0],"timer"))};a.fn.startCountDown=function(){this.doCountDown(a(this).attr("id"), a.data(this[0],"diffSecs"),500)};a.fn.setCountDown=function(b){var c=new Date;b.targetDate?c=new Date(b.targetDate.month+"/"+b.targetDate.day+"/"+b.targetDate.year+" "+b.targetDate.hour+":"+b.targetDate.min+":"+b.targetDate.sec+(b.targetDate.utc?" UTC":"")):b.targetOffset&&(c.setFullYear(b.targetOffset.year+c.getFullYear()),c.setMonth(b.targetOffset.month+c.getMonth()),c.setDate(b.targetOffset.day+c.getDate()),c.setHours(b.targetOffset.hour+c.getHours()),c.setMinutes(b.targetOffset.min+c.getMinutes()), c.setSeconds(b.targetOffset.sec+c.getSeconds()));diffSecs=Math.floor((c.valueOf()-(new Date).valueOf())/1E3);a.data(this[0],"diffSecs",diffSecs);return diffSecs};a.fn.doCountDown=function(b,c,d){$this=a("#"+b);0>=c&&(c=0,a.data($this[0],"timer")&&clearTimeout(a.data($this[0],"timer")));secs=c%60;mins=Math.floor(c/60)%60;hours=Math.floor(c/60/60)%24;days=!0==a.data($this[0],"omitWeeks")?Math.floor(c/60/60/24):Math.floor(c/60/60/24)%7;weeks=Math.floor(c/60/60/24/7);$this.dashChangeTo(b,"seconds_dash", secs,d?d:800);$this.dashChangeTo(b,"minutes_dash",mins,d?d:1200);$this.dashChangeTo(b,"hours_dash",hours,d?d:1200);$this.dashChangeTo(b,"days_dash",days,d?d:1200);$this.dashChangeTo(b,"weeks_dash",weeks,d?d:1200);a.data($this[0],"diffSecs",c);0<c?(e=$this,t=setTimeout(function(){e.doCountDown(b,c-1)},1E3),a.data(e[0],"timer",t)):(cb=a.data($this[0],"callback"))&&a.data($this[0],"callback")()};a.fn.dashChangeTo=function(b,c,d,m){$this=a("#"+b);for(b=$this.find("."+c+" .digit").length-1;0<=b;b--){var j= d%10,d=(d-j)/10;$this.digitChangeTo("#"+$this.attr("id")+" ."+c+" .digit:eq("+b+")",j,m)}};a.fn.digitChangeTo=function(b,c,d){d||(d=800);a(b+" div.top").html()!=c+""&&(a(b+" div.top").css({display:"none"}),a(b+" div.top").html(c?c:"0").slideDown(d),a(b+" div.bottom").animate({height:""},d,function(){a(b+" div.bottom").html(a(b+" div.top").html());a(b+" div.bottom").css({display:"block",height:""});a(b+" div.top").hide().slideUp(10)}))}})(jQuery); jQuery(document).ready(function(){$("#countdown").countDown({targetDate:{day:7,month:5,year:2012,hour:8,min:0,sec:0,utc:!0}})});$(document).ready(function(){$("#xtreme_slider").tinycarousel()}); (function(a){function b(c,b){function m(){b.controls&&0<n.length&&0<o.length&&(n.click(function(){g.move(-1);return!1}),o.click(function(){g.move(1);return!1}));b.interval&&c.hover(g.stop,g.start);b.pager&&0<p.length&&a("a",p).click(x)}function j(){b.controls&&(n.toggleClass("disable",!(0<f)),o.toggleClass("disable",!(f+1<h)));if(b.pager){var c=a(".pagenum",p);c.removeClass("active");a(c[f]).addClass("active")}}function x(){a(this).hasClass("pagenum")&&g.move(parseInt(this.rel),!0);return!1}function v(){b.interval&& !q&&(clearTimeout(r),r=setTimeout(function(){f=f+1==h?-1:f;s=f+1==h?!1:0==f?!0:s;g.move(s?1:-1)},b.intervaltime))}var g=this,w=a(".viewport:first",c),u=a(".overview:first",c),i=u.children(),o=a(".next:first",c),n=a(".prev:first",c),p=a(".pager:first",c),k,h,f,r,q,s=!0,l="x"==b.axis;this.stop=function(){clearTimeout(r);q=!0};this.start=function(){q=!1;v()};this.move=function(a,c){f=c?a:f+=a;if(-1<f&&f<h){var g={};g[l?"left":"top"]=-(f*k*b.display);u.animate(g,{queue:!1,duration:b.animation?b.duration: 0,complete:function(){"function"==typeof b.callback&&b.callback.call(this,i[f],f)}});j();v()}};return function(){k=l?a(i[0]).outerWidth(!0):a(i[0]).outerHeight(!0);var c=Math.ceil((l?w.outerWidth():w.outerHeight())/(k*b.display)-1);h=Math.max(1,Math.ceil(i.length/b.display)-c);f=Math.min(h,Math.max(1,b.start))-2;u.css(l?"width":"height",k*i.length);g.move(1);m();return g}()}a.tiny=a.tiny||{};a.tiny.carousel={options:{start:1,display:1,axis:"x",controls:!1,pager:!0,interval:!0,intervaltime:5E3,rewind:!1, animation:!0,duration:1E3,callback:null}};a.fn.tinycarousel=function(c){c=a.extend({},a.tiny.carousel.options,c);this.each(function(){a(this).data("tcl",new b(a(this),c))});return this};a.fn.tinycarousel_start=function(){a(this).data("tcl").start()};a.fn.tinycarousel_stop=function(){a(this).data("tcl").stop()};a.fn.tinycarousel_move=function(b){a(this).data("tcl").move(b-1,!0)}})(jQuery); 

誰かが私のスクリプトに基づいてjQueryのから未使用のコードを削除してくださいできますか?

+0

あなたはいくつかの潜在的なものに触れていますが、あなたの質問が何であるかを明確に述べることはありませんか? – Corbin

+0

また、Googleクローズ機能は便利ですが、手に入れたことを念頭に置いて作成されたコードでは使用しないことをおすすめします.YMMV – ZenMaster

+0

明確でない場合は申し訳ありません。私は今よりもっと明確な質問で投稿を編集しました。:) – Umer

答えて

1

ビルドスクリプト(source on github)を変更することで、カスタムjqueryビルドを試すことができます。または可能であればZeptoを試してみてください。このライブラリは非常に軽量で、jQuery互換のAPIを持っています。

また、related question

+0

それは今のところ私にとっては複雑すぎます! :( – Umer

1

Google Closureが簡単な上〜59%、または高度に〜65%てコードを減らすことができます。私は両方を試してみて、プロダクションサーバーでそれらを使用する前に両方が動作することを確認することをお勧めしますが、これはあなたが望むものと思われます。

また、コンパイル時には、の上部にある選択ボックスを使用して、のjQueryライブラリでコンパイルしてください。

関連する問題