UNPKG

yslowjs

Version:

Wrapper for phantomjs yslow.js

5 lines 139 kB
/** * Copyright (c) 2012, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var i,arg,page,urlCount,viewport,webpage=require("webpage"),args=phantom.args,len=args.length,urls=[],yslowArgs={info:"all",format:"json",ruleset:"ydefault",beacon:false,ua:false,viewport:false,headers:false,console:0,threshold:80},unaryArgs={help:false,version:false,dict:false,verbose:false},argsAlias={i:"info",f:"format",r:"ruleset",h:"help",V:"version",d:"dict",u:"ua",vp:"viewport",c:"console",b:"beacon",v:"verbose",t:"threshold",ch:"headers"};for(i=0;i<len;i+=1){arg=args[i];if(arg[0]!=="-"){if(arg.indexOf("http")!==0){arg="http://"+arg}urls.push(arg)}arg=arg.replace(/^\-\-?/,"");if(yslowArgs.hasOwnProperty(arg)){i+=1;yslowArgs[arg]=args[i]}else{if(yslowArgs.hasOwnProperty(argsAlias[arg])){i+=1;yslowArgs[argsAlias[arg]]=args[i]}else{if(unaryArgs.hasOwnProperty(arg)){unaryArgs[arg]=true}else{if(unaryArgs.hasOwnProperty(argsAlias[arg])){unaryArgs[argsAlias[arg]]=true}}}}}urlCount=urls.length;if(unaryArgs.version){console.log("3.1.5");phantom.exit()}if(len===0||urlCount===0||unaryArgs.help){console.log([""," Usage: phantomjs [phantomjs options] "+phantom.scriptName+" [yslow options] [url ...]",""," PhantomJS Options:",""," http://y.ahoo.it/phantomjs/options",""," YSlow Options:",""," -h, --help output usage information"," -V, --version output the version number"," -i, --info <info> specify the information to display/log (basic|grade|stats|comps|all) [all]"," -f, --format <format> specify the output results format (json|xml|plain|tap|junit) [json]"," -r, --ruleset <ruleset> specify the YSlow performance ruleset to be used (ydefault|yslow1|yblog) [ydefault]"," -b, --beacon <url> specify an URL to log the results"," -d, --dict include dictionary of results fields"," -v, --verbose output beacon response information"," -t, --threshold <score> for test formats, the threshold to test scores ([0-100]|[A-F]|{JSON}) [80]",' e.g.: -t B or -t 75 or -t \'{"overall": "B", "ycdn": "F", "yexpires": 85}\'',' -u, --ua "<user agent>" specify the user agent string sent to server when the page requests resources'," -vp, --viewport <WxH> specify page viewport size WxY, where W = width and H = height [400x300]",' -ch, --headers <JSON> specify custom request headers, e.g.: -ch \'{"Cookie": "foo=bar"}\''," -c, --console <level> output page console messages (0: none, 1: message, 2: message + line + source) [0]",""," Examples:",""," phantomjs "+phantom.scriptName+" http://yslow.org"," phantomjs "+phantom.scriptName+" -i grade -f xml www.yahoo.com www.cnn.com www.nytimes.com"," phantomjs "+phantom.scriptName+' -info all --format plain --ua "MSIE 9.0" http://yslow.org'," phantomjs "+phantom.scriptName+" -i basic --rulseset yslow1 -d http://yslow.org"," phantomjs "+phantom.scriptName+" -i grade -b http://www.showslow.com/beacon/yslow/ -v yslow.org"," phantomjs --load-plugins=yes "+phantom.scriptName+" -vp 800x600 http://www.yahoo.com"," phantomjs "+phantom.scriptName+" -i grade -f tap -t 85 http://yslow.org",""].join("\n"));phantom.exit()}yslowArgs.dict=unaryArgs.dict;yslowArgs.verbose=unaryArgs.verbose;urls.forEach(function(a){var c=webpage.create();c.resources={};c.settings.webSecurityEnabled=false;c.onResourceRequested=function(d){c.resources[d.url]={request:d}};c.onResourceReceived=function(d){var e,f=c.resources[d.url].response;if(!f){c.resources[d.url].response=d}else{for(e in d){if(d.hasOwnProperty(e)){f[e]=d[e]}}}};yslowArgs.console=parseInt(yslowArgs.console,10)||0;if(yslowArgs.console){if(yslowArgs.console===1){c.onConsoleMessage=function(d){console.log(d)};c.onError=function(d){console.error(d)}}else{c.onConsoleMessage=function(f,d,e){console.log(JSON.stringify({message:f,lineNumber:d,source:e},null,4))};c.onError=function(e,d){console.error(JSON.stringify({message:e,stacktrace:d}))}}}else{c.onError=function(){}}if(yslowArgs.ua){c.settings.userAgent=yslowArgs.ua}if(yslowArgs.viewport){viewport=yslowArgs.viewport.toLowerCase();c.viewportSize={width:parseInt(viewport.slice(0,viewport.indexOf("x")),10)||c.viewportSize.width,height:parseInt(viewport.slice(viewport.indexOf("x")+1),10)||c.viewportSize.height}}if(yslowArgs.headers){try{c.customHeaders=JSON.parse(yslowArgs.headers)}catch(b){console.log("Invalid custom headers: "+b)}}c.startTime=new Date();c.open(a,function(k){var f,j,m,n,l,d,h,e=c.startTime,g=c.resources;if(k!=="success"){console.log("FAIL to load "+d)}else{l=new Date()-e;for(d in g){if(g.hasOwnProperty(d)){h=g[d].response;if(h){h.time=new Date(h.time)-e}}}f=function(){if(typeof YSLOW==="undefined"){YSLOW={}}YSLOW.DEBUG=true;YSLOW.registerRule=function(o){YSLOW.controller.addRule(o)};YSLOW.registerRuleset=function(o){YSLOW.controller.addRuleset(o)};YSLOW.registerRenderer=function(o){YSLOW.controller.addRenderer(o)};YSLOW.registerTool=function(o){YSLOW.Tools.addCustomTool(o)};YSLOW.addEventListener=function(p,q,o){YSLOW.util.event.addListener(p,q,o)};YSLOW.removeEventListener=function(o,p){return YSLOW.util.event.removeListener(o,p)};YSLOW.Error=function(o,p){this.name=o;this.message=p};YSLOW.Error.prototype={toString:function(){return this.name+"\n"+this.message}};YSLOW.version="3.1.5";YSLOW.ComponentSet=function(o,p){this.root_node=o;this.components=[];this.outstanding_net_request=0;this.component_info=[];this.onloadTimestamp=p;this.nextID=1;this.notified_fetch_done=false};YSLOW.ComponentSet.prototype={clear:function(){this.components=[];this.component_info=[];this.cleared=true;if(this.outstanding_net_request>0){YSLOW.util.dump("YSLOW.ComponentSet.Clearing component set before all net requests finish.")}},addComponent:function(s,t,q,v){var p,u,r;if(!s){if(!this.empty_url){this.empty_url=[]}this.empty_url[t]=(this.empty_url[t]||0)+1}if(s&&t){if(!YSLOW.ComponentSet.isValidProtocol(s)||!YSLOW.ComponentSet.isValidURL(s)){return p}s=YSLOW.util.makeAbsoluteUrl(s,q);s=YSLOW.util.escapeHtml(s);u=typeof this.component_info[s]!=="undefined";r=t==="doc";if(!u||r){this.component_info[s]={state:"NONE",count:u?this.component_info[s].count:0};p=new YSLOW.Component(s,t,this,v);if(p){p.id=this.nextID+=1;this.components[this.components.length]=p;if(!this.doc_comp&&r){this.doc_comp=p}if(this.component_info[s].state==="NONE"){this.component_info[s].state="REQUESTED";this.outstanding_net_request+=1}}else{this.component_info[s].state="ERROR";YSLOW.util.event.fire("componentFetchError")}}this.component_info[s].count+=1}return p},addComponentNoDuplicate:function(p,q,o){if(p&&q){p=YSLOW.util.escapeHtml(p);p=YSLOW.util.makeAbsoluteUrl(p,o);if(this.component_info[p]===undefined){return this.addComponent(p,q,o)}}},getComponentsByType:function(B,y,r){var u,s,z,q,C,w,p,v=this.components,A=this.component_info,o=[],x={};if(typeof y==="undefined"){y=!(YSLOW.util.Preference.getPref("excludeAfterOnload",true))}if(typeof r==="undefined"){r=!(YSLOW.util.Preference.getPref("excludeBeaconsFromLint",true))}if(typeof B==="string"){x[B]=1}else{for(u=0,z=B.length;u<z;u+=1){C=B[u];if(C){x[C]=1}}}for(u=0,z=v.length;u<z;u+=1){w=v[u];if(!w||(w&&!x[w.type])||(w.is_beacon&&!r)||(w.after_onload&&!y)){continue}o[o.length]=w;p=A[u];if(!p||(p&&p.count<=1)){continue}for(s=1,q=p.count;s<q;s+=1){o[o.length]=w}}return o},getProgress:function(){var o,p=0,q=0;for(o in this.component_info){if(this.component_info.hasOwnProperty(o)&&this.component_info[o]){if(this.component_info[o].state==="RECEIVED"){q+=1}p+=1}}return{total:p,received:q}},onComponentGetInfoStateChange:function(r){var o,q,p;if(r){if(typeof r.comp!=="undefined"){o=r.comp}if(typeof r.state!=="undefined"){q=r.state}}if(typeof this.component_info[o.url]==="undefined"){YSLOW.util.dump("YSLOW.ComponentSet.onComponentGetInfoStateChange(): Unexpected component: "+o.url);return}if(this.component_info[o.url].state==="NONE"&&q==="DONE"){this.component_info[o.url].state="RECEIVED"}else{if(this.component_info[o.url].state==="REQUESTED"&&q==="DONE"){this.component_info[o.url].state="RECEIVED";this.outstanding_net_request-=1;if(this.outstanding_net_request===0){this.notified_fetch_done=true;YSLOW.util.event.fire("componentFetchDone",{component_set:this})}}else{YSLOW.util.dump("Unexpected component info state: ["+o.type+"]"+o.url+"state: "+q+" comp_info_state: "+this.component_info[o.url].state)}}p=this.getProgress();YSLOW.util.event.fire("componentFetchProgress",{total:p.total,current:p.received,last_component_url:o.url})},notifyPeelDone:function(){if(this.outstanding_net_request===0&&!this.notified_fetch_done){this.notified_fetch_done=true;YSLOW.util.event.fire("componentFetchDone",{component_set:this})}},setSimpleAfterOnload:function(t,y){var B,A,E,p,u,v,q,s,o,r,C,D,x,F,z,w;if(y){x=y.docBody;F=y.doc;z=y.components;w=y.components}else{x=this.doc_comp&&this.doc_comp.body;F=this.root_node;z=this.components;w=this}if(!x){YSLOW.util.dump("doc body is empty");return t(w)}p=F.createElement("div");p.innerHTML=x;u=p.getElementsByTagName("*");for(B=0,C=z.length;B<C;B+=1){E=z[B];r=E.type;if(r==="cssimage"||r==="doc"){continue}q=false;s=E.url;for(A=0,D=u.length;!q&&A<D;A+=1){o=u[A];v=o.src||o.href||o.getAttribute("src")||o.getAttribute("href")||(o.nodeName==="PARAM"&&o.value);q=(v===s)}E.after_onload=!q}t(w)},setAfterOnload:function(q,w){var y,D,G,v,A,o,s,t,L,x,J,r,u,p=YSLOW.util,B=p.addEventListener,C=p.removeEventListener,I=setTimeout,F=clearTimeout,z=[],K={},H=function(Q){var O,M,P,R,N;F(v);O=Q.type;M=Q.attrName;P=Q.target;R=P.src||P.href||(P.getAttribute&&(P.getAttribute("src")||P.getAttribute("href")));N=P.dataOldSrc;if(R&&(O==="DOMNodeInserted"||(O==="DOMSubtreeModified"&&R!==N)||(O==="DOMAttrModified"&&(M==="src"||M==="href")))&&!K[R]){K[R]=1;z.push(P)}v=I(A,1000)},E=function(){var N,M,P,O,Q;F(o);P=D.getElementsByTagName("*");for(N=0,M=P.length;N<M;N+=1){O=P[N];Q=O.src||O.href;if(Q){O.dataOldSrc=Q}}B(G,"DOMSubtreeModified",H);B(G,"DOMNodeInserted",H);B(G,"DOMAttrModified",H);v=I(A,3000);r=I(A,10000)};if(w){s=YSLOW.ComponentSet.prototype;t=w.docBody;L=w.doc;x=w.components;J=x}else{s=this;t=s.doc_comp&&s.doc_comp.body;L=s.root_node;x=s.components;J=s}if(typeof MutationEvent==="undefined"||YSLOW.antiIframe){return s.setSimpleAfterOnload(q,w)}if(!t){p.dump("doc body is empty");return q(J)}A=function(){var Q,P,N,M,O,S,R;if(u){return}F(r);F(v);C(G,"DOMSubtreeModified",H);C(G,"DOMNodeInserted",H);C(G,"DOMAttrModified",H);C(y,"load",E);C(G,"load",E);for(Q=0,N=z.length;Q<N;Q+=1){O=z[Q];S=O.src||O.href||(O.getAttribute&&(O.getAttribute("src")||O.getAttribute("href")));if(!S){continue}for(P=0,M=x.length;P<M;P+=1){R=x[P];if(R.url===S){R.after_onload=true}}}y.parentNode.removeChild(y);u=1;q(J)};y=L.createElement("iframe");y.style.cssText="position:absolute;top:-999em;";L.body.appendChild(y);G=y.contentWindow;o=I(A,3000);if(G){D=G.document}else{G=D=y.contentDocument}B(G,"load",E);B(y,"load",E);D.open().write(t);D.close();B(G,"load",E)}};YSLOW.ComponentSet.ignoreProtocols=["data","chrome","javascript","about","resource","jar","chrome-extension","file"];YSLOW.ComponentSet.isValidProtocol=function(r){var q,p,u,t=this.ignoreProtocols,o=t.length;r=r.toLowerCase();p=r.indexOf(":");if(p>0){u=r.substr(0,p);for(q=0;q<o;q+=1){if(u===t[q]){return false}}}return true};YSLOW.ComponentSet.isValidURL=function(p){var o,q;p=p.toLowerCase();o=p.split(":");if(o[0]==="http"||o[0]==="https"){if(o[1].substr(0,2)!=="//"){return false}q=o[1].substr(2);if(q.length===0||q.indexOf("/")===0){return false}}return true};YSLOW.Component=function(q,r,t,u){var s=u&&u.obj,p=(u&&u.comp)||{};this.url=q;this.type=r;this.parent=t;this.headers={};this.raw_headers="";this.req_headers=null;this.body="";this.compressed=false;this.expires=undefined;this.size=0;this.status=0;this.is_beacon=false;this.method="unknown";this.cookie="";this.respTime=null;this.after_onload=false;this.object_prop=undefined;if(r===undefined){this.type="unknown"}this.get_info_state="NONE";if(s&&r==="image"&&s.width&&s.height){this.object_prop={width:s.width,height:s.height}}if(p.containerNode){this.containerNode=p.containerNode}this.setComponentDetails(u)};YSLOW.Component.prototype.getInfoState=function(){return this.get_info_state};YSLOW.Component.prototype.populateProperties=function(y,q){var t,o,p,v,w,s,x,u=this,r=null,z="undefined";if(u.headers.location&&y){t=u.parent.addComponentNoDuplicate(u.headers.location,(u.type!=="redirect"?u.type:"unknown"),u.url);if(t&&u.after_onload){t.after_onload=true}u.type="redirect"}v=u.headers["content-length"];o=YSLOW.util.trim(u.headers["content-encoding"]);if(o==="gzip"||o==="deflate"){u.compressed=o;u.size=(u.body.length)?u.body.length:r;if(v){u.size_compressed=parseInt(v,10)||v}else{if(typeof u.nsize!==z){u.size_compressed=u.nsize}else{u.size_compressed=Math.round(u.size/3)}}}else{u.compressed=false;u.size_compressed=r;if(v){u.size=parseInt(v,10)}else{if(typeof u.nsize!==z){u.size=parseInt(u.nsize,10)}else{u.size=u.body.length}}}if(!u.size){if(typeof u.nsize!==z){u.size=u.nsize}else{u.size=u.body.length}}u.uncompressed_size=u.body.length;p=u.headers.expires;if(p&&p.length>0){u.expires=new Date(p);if(u.expires.toString()==="Invalid Date"){u.expires=u.getMaxAge()}}else{u.expires=u.getMaxAge()}if(u.type==="image"&&!q){if(typeof Image!==z){s=new Image()}else{s=document.createElement("img")}if(u.body.length){w="data:"+u.headers["content-type"]+";base64,"+YSLOW.util.base64Encode(u.body);x=1}else{w=u.url}s.onerror=function(){s.onerror=r;if(x){s.src=u.url}};s.onload=function(){s.onload=r;if(s&&s.width&&s.height){if(u.object_prop){u.object_prop.actual_width=s.width;u.object_prop.actual_height=s.height}else{u.object_prop={width:s.width,height:s.height,actual_width:s.width,actual_height:s.height}}if(s.width<2&&s.height<2){u.is_beacon=true}}};s.src=w}};YSLOW.Component.prototype.hasOldModifiedDate=function(){var o=Number(new Date()),p=this.headers["last-modified"];if(typeof p!=="undefined"){return((o-Number(new Date(p)))>(24*60*60*1000))}return false};YSLOW.Component.prototype.hasFarFutureExpiresOrMaxAge=function(){var r,p=Number(new Date()),q=YSLOW.util.Preference.getPref("minFutureExpiresSeconds",2*24*60*60),o=q*1000;if(typeof this.expires==="object"){r=Number(this.expires);if((r-p)>o){return true}}return false};YSLOW.Component.prototype.getEtag=function(){return this.headers.etag||""};YSLOW.Component.prototype.getMaxAge=function(){var p,q,o,r=this.headers["cache-control"];if(r){p=r.indexOf("max-age");if(p>-1){q=parseInt(r.substring(p+8),10);if(q>0){o=YSLOW.util.maxAgeToDate(q)}}}return o};YSLOW.Component.prototype.getSetCookieSize=function(){var q,o,p=0;if(this.headers&&this.headers["set-cookie"]){q=this.headers["set-cookie"].split("\n");if(q.length>0){for(o=0;o<q.length;o+=1){p+=q[o].length}}}return p};YSLOW.Component.prototype.getReceivedCookieSize=function(){var q,o,p=0;if(this.cookie&&this.cookie.length>0){q=this.cookie.split("\n");if(q.length>0){for(o=0;o<q.length;o+=1){p+=q[o].length}}}return p};YSLOW.Component.prototype.setComponentDetails=function(r){var p=this,q=function(t,o){var u;p.status=o.status;p.headers={};p.raw_headers="";o.headers.forEach(function(v){p.headers[v.name.toLowerCase()]=v.value;p.raw_headers+=v.name+": "+v.value+"\n"});p.req_headers={};t.headers.forEach(function(v){p.req_headers[v.name.toLowerCase()]=v.value});p.method=t.method;if(o.contentText){p.body=o.contentText}else{try{u=new XMLHttpRequest();u.open("GET",p.url,false);u.send();p.body=u.responseText}catch(s){p.body={toString:function(){return""},length:o.bodySize||0}}}p.response_type=p.type;p.cookie=(p.headers["set-cookie"]||"")+(p.req_headers.cookie||"");p.nsize=parseInt(p.headers["content-length"],10)||o.bodySize;p.respTime=o.time;p.after_onload=(new Date(t.time).getTime())>p.parent.onloadTimestamp;p.populateProperties(false,true);p.get_info_state="DONE";p.parent.onComponentGetInfoStateChange({comp:p,state:"DONE"})};if(r.request&&r.response){q(r.request,r.response)}};YSLOW.controller={rules:{},rulesets:{},onloadTimestamp:null,renderers:{},default_ruleset_id:"ydefault",run_pending:0,init:function(){var p,o,r,q;YSLOW.util.event.addListener("onload",function(s){this.onloadTimestamp=s.time;YSLOW.util.setTimer(function(){YSLOW.controller.run_pending_event()})},this);YSLOW.util.event.addListener("onUnload",function(s){this.run_pending=0;this.onloadTimestamp=null},this);p=YSLOW.util.Preference.getPrefList("customRuleset.",undefined);if(p&&p.length>0){for(o=0;o<p.length;o+=1){q=p[o].value;if(typeof q==="string"&&q.length>0){r=JSON.parse(q,null);r.custom=true;this.addRuleset(r)}}}this.default_ruleset_id=YSLOW.util.Preference.getPref("defaultRuleset","ydefault");this.loadRulePreference()},run:function(r,s,p){var t,o,q=r.document;if(!q||!q.location||q.location.href.indexOf("about:")===0||"undefined"===typeof q.location.hostname){if(!p){o="Please enter a valid website address before running YSlow.";YSLOW.ysview.openDialog(YSLOW.ysview.panel_doc,389,150,o,"","Ok")}return}if(!s.PAGE.loaded){this.run_pending={win:r,yscontext:s};return}YSLOW.util.event.fire("peelStart",undefined);t=YSLOW.peeler.peel(q,this.onloadTimestamp);s.component_set=t;YSLOW.util.event.fire("peelComplete",{component_set:t});t.notifyPeelDone()},run_pending_event:function(){if(this.run_pending){this.run(this.run_pending.win,this.run_pending.yscontext,false);this.run_pending=0}},lint:function(F,q,o){var r,v,D,u,w,x,E,C=[],A=[],B=0,z=0,s=this,t=s.rulesets,y=s.default_ruleset_id;if(o){C=t[o]}else{if(y&&t[y]){C=t[y]}else{for(D in t){if(t.hasOwnProperty(D)&&t[D]){C=t[D];break}}}}v=C.rules;for(D in v){if(v.hasOwnProperty(D)&&v[D]&&this.rules.hasOwnProperty(D)){try{r=this.rules[D];u=YSLOW.util.merge(r.config,v[D]);w=r.lint(F,q.component_set,u);x=(C.weights?C.weights[D]:undefined);if(x!==undefined){x=parseInt(x,10)}if(x===undefined||x<0||x>100){if(t.ydefault.weights[D]){x=t.ydefault.weights[D]}else{x=5}}w.weight=x;if(w.score!==undefined){if(typeof w.score!=="number"){E=parseInt(w.score,10);if(!isNaN(E)){w.score=E}}if(typeof w.score==="number"){z+=w.weight;if(!YSLOW.util.Preference.getPref("allowNegativeScore",false)){if(w.score<0){w.score=0}if(typeof w.score!=="number"){w.score=-1}}if(w.score!==0){B+=w.score*(typeof w.weight!=="undefined"?w.weight:1)}}}w.name=r.name;w.category=r.category;w.rule_id=D;A[A.length]=w}catch(p){YSLOW.util.dump("YSLOW.controller.lint: "+D,p);YSLOW.util.event.fire("lintError",{rule:D,message:p})}}}q.PAGE.overallScore=B/(z>0?z:1);q.result_set=new YSLOW.ResultSet(A,q.PAGE.overallScore,C);q.result_set.url=q.component_set.doc_comp.url;YSLOW.util.event.fire("lintResultReady",{yslowContext:q});return q.result_set},runTool:function(B,y,p){var E,u,A,t,w,o,z,q,D,C,v,x=YSLOW.Tools.getTool(B);try{if(typeof x==="object"){E=x.run(y.document,y.component_set,p);if(x.print_output){u="";if(typeof E==="object"){u=E.html}else{if(typeof E==="string"){u=E}}A=YSLOW.util.getNewDoc();v=A.body||A.documentElement;v.innerHTML=u;t=A.getElementsByTagName("head")[0];if(typeof E.css==="undefined"){o="chrome://yslow/content/yslow/tool.css";z=new XMLHttpRequest();z.open("GET",o,false);z.send(null);w=z.responseText}else{w=E.css}if(typeof w==="string"){q=A.createElement("style");q.setAttribute("type","text/css");q.appendChild(A.createTextNode(w));t.appendChild(q)}if(typeof E.js!=="undefined"){D=A.createElement("script");D.setAttribute("type","text/javascript");D.appendChild(A.createTextNode(E.js));t.appendChild(D)}if(typeof E.plot_component!=="undefined"&&E.plot_component===true){YSLOW.renderer.plotComponents(A,y)}}}else{C=B+" is not a tool.";YSLOW.util.dump(C);YSLOW.util.event.fire("toolError",{tool_id:B,message:C})}}catch(r){YSLOW.util.dump("YSLOW.controller.runTool: "+B,r);YSLOW.util.event.fire("toolError",{tool_id:B,message:r})}},render:function(s,o,r){var q=this.renderers[s],p="";if(q.supports[o]!==undefined&&q.supports[o]===1){switch(o){case"components":p=q.componentsView(r.comps,r.total_size);break;case"reportcard":p=q.reportcardView(r.result_set);break;case"stats":p=q.statsView(r.stats);break;case"tools":p=q.toolsView(r.tools);break;case"rulesetEdit":p=q.rulesetEditView(r.rulesets);break}}return p},getRenderer:function(o){return this.renderers[o]},addRule:function(q){var o,p,r=["id","name","config","info","lint"];if(YSLOW.doc.rules&&YSLOW.doc.rules[q.id]){p=YSLOW.doc.rules[q.id];if(p.name){q.name=p.name}if(p.info){q.info=p.info}}for(o=0;o<r.length;o+=1){if(typeof q[r[o]]==="undefined"){throw new YSLOW.Error("Interface error","Improperly implemented rule interface")}}if(this.rules[q.id]!==undefined){throw new YSLOW.Error("Rule register error",q.id+" is already defined.")}this.rules[q.id]=q},addRuleset:function(o,r){var p,q=["id","name","rules"];for(p=0;p<q.length;p+=1){if(typeof o[q[p]]==="undefined"){throw new YSLOW.Error("Interface error","Improperly implemented ruleset interface")}if(this.checkRulesetName(o.id)&&r!==true){throw new YSLOW.Error("Ruleset register error",o.id+" is already defined.")}}this.rulesets[o.id]=o},removeRuleset:function(p){var o=this.rulesets[p];if(o&&o.custom===true){delete this.rulesets[p];if(this.default_ruleset_id===p){this.default_ruleset_id="ydefault";YSLOW.util.Preference.setPref("defaultRuleset",this.default_ruleset_id)}return o}return null},saveRulesetToPref:function(o){if(o.custom===true){YSLOW.util.Preference.setPref("customRuleset."+o.id,JSON.stringify(o,null,2))}},deleteRulesetFromPref:function(o){if(o.custom===true){YSLOW.util.Preference.deletePref("customRuleset."+o.id)}},getRuleset:function(o){return this.rulesets[o]},addRenderer:function(o){this.renderers[o.id]=o},getRegisteredRuleset:function(){return this.rulesets},getRegisteredRules:function(){return this.rules},getRule:function(o){return this.rules[o]},checkRulesetName:function(q){var r,p,o=this.rulesets;q=q.toLowerCase();for(r in o){if(o.hasOwnProperty(r)){p=o[r];if(p.id.toLowerCase()===q||p.name.toLowerCase()===q){return true}}}return false},setDefaultRuleset:function(o){if(this.rulesets[o]!==undefined){this.default_ruleset_id=o;YSLOW.util.Preference.setPref("defaultRuleset",o)}},getDefaultRuleset:function(){if(this.rulesets[this.default_ruleset_id]===undefined){this.setDefaultRuleset("ydefault")}return this.rulesets[this.default_ruleset_id]},getDefaultRulesetId:function(){return this.default_ruleset_id},loadRulePreference:function(){var p=this.getRule("yexpires"),o=YSLOW.util.Preference.getPref("minFutureExpiresSeconds",2*24*60*60);if(o>0&&p){p.config.howfar=o}}};YSLOW.util={merge:function(q,p){var r,s={};for(r in q){if(q.hasOwnProperty(r)){s[r]=q[r]}}for(r in p){if(p.hasOwnProperty(r)){s[r]=p[r]}}return s},dump:function(){var o;if(!YSLOW.DEBUG){return}o=Array.prototype.slice.apply(arguments);o=o&&o.length===1?o[0]:o;try{if(typeof Firebug!=="undefined"&&Firebug.Console&&Firebug.Console.log){Firebug.Console.log(o)}else{if(typeof Components!=="undefined"&&Components.classes&&Components.interfaces){Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage(JSON.stringify(o,null,2))}}}catch(q){try{console.log(o)}catch(p){}}},filter:function(r,s,p){var q,o=p?[]:{};for(q in r){if(r.hasOwnProperty(q)&&s(q,r[q])){o[p?o.length:q]=r[q]}}return o},expires_month:{Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12},prettyExpiresDate:function(o){var p;if(Object.prototype.toString.call(o)==="[object Date]"&&o.toString()!=="Invalid Date"&&!isNaN(o)){p=o.getMonth()+1;return o.getFullYear()+"/"+p+"/"+o.getDate()}else{if(!o){return"no expires"}}return"invalid date object"},maxAgeToDate:function(p){var o=new Date();o=o.getTime()+parseInt(p,10)*1000;return new Date(o)},plural:function(q,r){var p,o=q,s={are:["are","is"],s:["s",""],"do":["do","does"],num:[r,r]};for(p in s){if(s.hasOwnProperty(p)){o=o.replace(new RegExp("%"+p+"%","gm"),(r===1)?s[p][1]:s[p][0])}}return o},countExpressions:function(q){var o=0,p;p=q.indexOf("expression(");while(p!==-1){o+=1;p=q.indexOf("expression(",p+1)}return o},countAlphaImageLoaderFilter:function(t){var r,s,q,u,p=0,v=0,o={};r=t.indexOf("filter:");while(r!==-1){q=false;if(r>0&&t.charAt(r-1)==="_"){q=true}s=t.indexOf(";",r+7);if(s!==-1){u=t.substring(r+7,s);if(u.indexOf("AlphaImageLoader")!==-1){if(q){v+=1}else{p+=1}}}r=t.indexOf("filter:",r+1)}if(v>0){o.hackFilter=v}if(p>0){o.filter=p}return o},getHostname:function(p){var o=p.split("/")[2];return(o&&o.split(":")[0])||""},getUniqueDomains:function(u,s){var r,p,t,o={},q=[];for(r=0,p=u.length;r<p;r+=1){t=u[r].url.split("/");if(t[2]){o[t[2].split(":")[0]]=1}}for(r in o){if(o.hasOwnProperty(r)){if(!s){q.push(r)}else{t=r.split(".");if(isNaN(parseInt(t[t.length-1],10))){q.push(r)}}}}return q},summaryByDomain:function(p,z,q){var v,u,y,t,A,s,w,r,B,x,C={},o=[];z=[].concat(z);r=z.length;for(v=0,y=p.length;v<y;v+=1){w=p[v];t=w.url.split("/");if(t[2]){A=t[2].split(":")[0];s=C[A];if(!s){s={domain:A,count:0};C[A]=s}s.count+=1;for(u=0;u<r;u+=1){B=z[u];x=s["sum_"+B]||0;x+=parseInt(w[B],10)||0;s["sum_"+B]=x}}}for(s in C){if(C.hasOwnProperty(s)){if(!q){o.push(C[s])}else{t=s.split(".");if(isNaN(parseInt(t[t.length-1],10))){o.push(C[s])}}}}return o},isMinified:function(q){var o=q.length,p;if(o===0){return true}p=q.replace(/\n| {2}|\t|\r/g,"").length;if(((o-p)/o)>0.2){return false}return true},isETagGood:function(o){var q=/^[0-9a-f]+:[0-9a-f]+$/,p=/^[0-9a-f]+\-[0-9a-f]+\-[0-9a-f]+$/;if(!o){return true}o=o.replace(/^["']|["'][\s\S]*$/g,"");return !(p.test(o)||q.test(o))},getComponentType:function(o){var p="unknown";if(o&&typeof o==="string"){if(o==="text/html"||o==="text/plain"){p="doc"}else{if(o==="text/css"){p="css"}else{if(/javascript/.test(o)){p="js"}else{if(/flash/.test(o)){p="flash"}else{if(/image/.test(o)){p="image"}else{if(/font/.test(o)){p="font"}}}}}}}return p},base64Encode:function(t){var s,r,q,v,p="",u=0,o=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"];for(s=0;s<t.length;s+=3){r=t.charCodeAt(s);if((s+1)<t.length){q=t.charCodeAt(s+1)}else{q=0;u+=1}if((s+2)<t.length){v=t.charCodeAt(s+2)}else{v=0;u+=1}p+=o[(r&252)>>2];p+=o[((r&3)<<4)|((q&240)>>4)];if(u>0){p+="="}else{p+=o[((q&15)<<2)|((v&192)>>6)]}if(u>1){p+="="}else{p+=o[(v&63)]}}return p},getXHR:function(){var o=0,r=null,p=["MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];if(typeof XMLHttpRequest==="function"){return new XMLHttpRequest()}for(o=0;o<p.length;o+=1){try{r=new ActiveXObject(p[o]);break}catch(q){}}return r},getComputedStyle:function(t,p,o){var s,r,q="";if(t.currentStyle){q=t.currentStyle[p]}if(t.ownerDocument&&t.ownerDocument.defaultView&&document.defaultView.getComputedStyle){s=t.ownerDocument.defaultView.getComputedStyle(t,"");if(s){q=s[p]}}if(!o){return q}if(typeof q!=="string"){return false}r=q.match(/\burl\((\'|\"|)([^\'\"]+?)\1\)/);if(r){return r[2]}else{return false}},escapeHtml:function(o){return(o||"").toString().replace(/</g,"&lt;").replace(/>/g,"&gt;")},escapeQuotes:function(p,o){if(o==="single"){return p.replace(/\'/g,"\\'")}if(o==="double"){return p.replace(/\"/g,'\\"')}return p.replace(/\'/g,"\\'").replace(/\"/g,'\\"')},formatHeaderName:(function(){var o={"content-md5":"Content-MD5",dnt:"DNT",etag:"ETag",p3p:"P3P",te:"TE","www-authenticate":"WWW-Authenticate","x-att-deviceid":"X-ATT-DeviceId","x-cdn":"X-CDN","x-ua-compatible":"X-UA-Compatible","x-xss-protection":"X-XSS-Protection"};return function(q){var p=q.toLowerCase();if(o.hasOwnProperty(p)){return o[p]}else{return p.replace(/(^|-)([a-z])/g,function(r,s,t){return s+t.toUpperCase()})}}}()),mod:function(o,p){return Math.round(o-(Math.floor(o/p)*p))},briefUrl:function(q,o){var p,r,s,t;o=o||100;if(q===undefined){return""}p=q.indexOf("//");if(-1!==p){r=q.indexOf("?");if(-1!==r){q=q.substring(0,r)+"?..."}if(q.length>o){s=q.indexOf("/",p+2);t=q.lastIndexOf("/");if(-1!==s&&-1!==t&&s!==t){q=q.substring(0,s+1)+"..."+q.substring(t)}else{q=q.substring(0,o+1)+"..."}}}return q},prettyAnchor:function(w,p,r,q,u,o,x){var s,v="",t="",y=0;if(typeof p==="undefined"){p=w}if(typeof r==="undefined"){r=""}else{r=' class="'+r+'"'}if(typeof u==="undefined"){u=100}if(typeof o==="undefined"){o=1}x=(x)?' rel="'+x+'"':"";p=YSLOW.util.escapeHtml(p);w=YSLOW.util.escapeHtml(w);s=YSLOW.util.escapeQuotes(p,"double");if(q){w=YSLOW.util.briefUrl(w,u);v=' title="'+s+'"'}while(0<w.length){t+="<a"+x+r+v+' href="'+s+'" onclick="javascript:document.ysview.openLink(\''+YSLOW.util.escapeQuotes(p)+"'); return false;\">"+w.substring(0,u);w=w.substring(u);y+=1;if(y>=o){if(0<w.length){t+="[snip]"}t+="</a>";break}else{t+="</a><font style='font-size: 0px;'> </font>"}}return t},kbSize:function(o){var p=o%(o>100?100:10);o-=p;return parseFloat(o/1000)+(0===(o%1000)?".0":"")+"K"},prettyTypes:{image:"Image",doc:"HTML/Text",cssimage:"CSS Image",css:"Stylesheet File",js:"JavaScript File",flash:"Flash Object",iframe:"IFrame",xhr:"XMLHttpRequest",redirect:"Redirect",favicon:"Favicon",unknown:"Unknown"},prettyType:function(o){return YSLOW.util.prettyTypes[o]},prettyScore:function(p){var o="F";if(!parseInt(p,10)&&p!==0){return p}if(p===-1){return"N/A"}if(p>=90){o="A"}else{if(p>=80){o="B"}else{if(p>=70){o="C"}else{if(p>=60){o="D"}else{if(p>=50){o="E"}}}}}return o},getResults:function(u,Q){var M,J,H,s,r,F,R,E,D,v,t,p,U,O,G,q,C,B,w,y,L,I,z,x=/ <button [\s\S]+<\/button>/,o=YSLOW.util,A=o.isArray,T={},N={},K=[],S={},P={};Q=(Q||"basic").split(",");for(M=0,O=Q.length;M<O;M+=1){if(Q[M]==="all"){G=C=q=true;break}else{switch(Q[M]){case"grade":G=true;break;case"stats":C=true;break;case"comps":q=true;break}}}S.w=parseInt(u.PAGE.totalSize,10);S.o=parseInt(u.PAGE.overallScore,10);S.u=encodeURIComponent(u.result_set.url);S.r=parseInt(u.PAGE.totalRequests,10);y=o.getPageSpaceid(u.component_set);if(y){S.s=encodeURI(y)}S.i=u.result_set.getRulesetApplied().id;if(u.PAGE.t_done){S.lt=parseInt(u.PAGE.t_done,10)}if(G){H=u.result_set.getResults();for(M=0,O=H.length;M<O;M+=1){D={};B=H[M];if(B.hasOwnProperty("score")){if(B.score>=0){D.score=parseInt(B.score,10)}else{if(B.score===-1){D.score="n/a"}}}D.message=B.message.replace(/javascript:document\.ysview\.openLink\('(.+)'\)/,"$1");F=B.components;if(A(F)){D.components=[];for(J=0,w=F.length;J<w;J+=1){R=F[J];if(typeof R==="string"){s=R}else{if(typeof R.url==="string"){s=R.url}}if(s){s=encodeURIComponent(s.replace(x,""));D.components.push(s)}}}P[B.rule_id]=D}S.g=P}if(C){S.w_c=parseInt(u.PAGE.totalSizePrimed,10);S.r_c=parseInt(u.PAGE.totalRequestsPrimed,10);for(r in u.PAGE.totalObjCount){if(u.PAGE.totalObjCount.hasOwnProperty(r)){T[r]={r:u.PAGE.totalObjCount[r],w:u.PAGE.totalObjSize[r]}}}S.stats=T;for(r in u.PAGE.totalObjCountPrimed){if(u.PAGE.totalObjCountPrimed.hasOwnProperty(r)){N[r]={r:u.PAGE.totalObjCountPrimed[r],w:u.PAGE.totalObjSizePrimed[r]}}}S.stats_c=N}if(q){F=u.component_set.components;for(M=0,O=F.length;M<O;M+=1){R=F[M];E=encodeURIComponent(R.url);D={type:R.type,url:E,size:R.size,resp:R.respTime};if(R.size_compressed){D.gzip=R.size_compressed}if(R.expires&&R.expires instanceof Date){D.expires=o.prettyExpiresDate(R.expires)}v=R.getReceivedCookieSize();if(v>0){D.cr=v}t=R.getSetCookieSize();if(t>0){D.cs=t}p=R.getEtag();if(typeof p==="string"&&p.length>0){D.etag=p}D.headers={};if(R.req_headers){I=R.req_headers;D.headers.request={};z=D.headers.request;for(L in I){if(I.hasOwnProperty(L)){z[o.formatHeaderName(L)]=I[L]}}}if(R.headers){I=R.headers;D.headers.response={};z=D.headers.response;for(L in I){if(I.hasOwnProperty(L)){z[o.formatHeaderName(L)]=I[L]}}}K.push(D)}S.comps=K}return S},sendBeacon:function(t,s,p){var u,x,y,q,v,r="",w=YSLOW.util,z=w.Preference,o="get";s=(s||"basic").split(",");for(u=0,x=s.length;u<x;u+=1){if(s[u]==="all"){o="post";break}else{switch(s[u]){case"grade":o="post";break;case"stats":o="post";break;case"comps":o="post";break}}}if(o==="post"){r=JSON.stringify(t,null);y=w.getXHR();y.open("POST",p,true);y.setRequestHeader("Content-Length",r.length);y.setRequestHeader("Content-Type","application/json");y.send(r)}else{for(q in t){if(t.hasOwnProperty(q)){r+=q+"="+t[q]+"&"}}v=new Image();v.src=p+"?"+r}return r},getDict:function(r,z){var v,x,q,u,o,y,t,p=YSLOW,w=p.controller,A=p.doc.rules,s={w:"size",o:"overall score",u:"url",r:"total number of requests",s:"space id of the page",i:"id of the ruleset used",lt:"page load time",grades:"100 >= A >= 90 > B >= 80 > C >= 70 > D >= 60 > E >= 50 > F >= 0 > N/A = -1"};r=(r||"basic").split(",");z=z||"ydefault";y=w.rulesets[z].weights;for(v=0,x=r.length;v<x;v+=1){if(r[v]==="all"){q=u=o=true;break}else{switch(r[v]){case"grade":q=true;break;case"stats":u=true;break;case"comps":o=true;break}}}if(q){s.g="scores of all rules in the ruleset";s.rules={};for(t in y){if(y.hasOwnProperty(t)){s.rules[t]=A[t];s.rules[t].weight=y[t]}}}if(u){s.w_c="page weight with primed cache";s.r_c="number of requests with primed cache";s.stats="number of requests and weight grouped by component type";s.stats_c="number of request and weight of components group by component type with primed cache"}if(o){s.comps="array of all the components found on the page"}return s},isObject:function(p){return Object.prototype.toString.call(p).indexOf("Object")>-1},isArray:function(p){if(Array.isArray){return Array.isArray(p)}else{return Object.prototype.toString.call(p).indexOf("Array")>-1}},decodeURIComponent:function(p){try{return decodeURIComponent(p)}catch(o){return p}},decodeEntities:function(o){return String(o).replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"')},safeXML:(function(){var o=this.decodeURIComponent,p=/[<&>]/;return function(q,r){if(r){q=o(q)}if(p.test(q)){return"<![CDATA["+q+"]]>"}return q}}()),objToXML:function(s,q){var o,p=YSLOW.util,t=p.safeXML,r='<?xml version="1.0" encoding="UTF-8"?>';o=function(A){var x,y,v,u,z,w;for(x in A){if(A.hasOwnProperty(x)){y=A[x];r+="<"+x+">";if(p.isArray(y)){for(v=0,u=y.length;v<u;v+=1){z=y[v];w=typeof z;r+="<item>";if(w==="string"||w==="number"){r+=t(z,x==="components")}else{o(z)}r+="</item>"}}else{if(p.isObject(y)){o(y)}else{r+=t(y,x==="u"||x==="url")}}r+="</"+x+">"}}};q=q||"results";r+="<"+q+">";o(s);r+="</"+q+">";return r},prettyPrintResults:function(s){var q,p=YSLOW.util,t="",r={},u={w:"size",o:"overall score",u:"url",r:"# of requests",s:"space id",i:"ruleset",lt:"page load time",g:"scores",w_c:"page size (primed cache)",r_c:"# of requests (primed cache)",stats:"statistics by component",stats_c:"statistics by component (primed cache)",comps:"components found on the page",components:"offenders",cr:"received cookie size",cs:"set cookie size",resp:"response time"},o=function(x){var v,w=r[x];if(typeof w==="undefined"){v=[];v.length=(4*x)+1;r[x]=w=v.join(" ")}return w};q=function(B,C){var y,z,w,v,A,x;for(y in B){if(B.hasOwnProperty(y)){z=B[y];t+=o(C)+(u[y]||y)+":";if(p.isArray(z)){t+="\n";for(w=0,v=z.length;w<v;w+=1){A=z[w];x=typeof A;if(x==="string"||x==="number"){t+=o(C+1)+p.decodeURIComponent(A)+"\n"}else{q(A,C+1);if(w<v-1){t+="\n"}}}}else{if(p.isObject(z)){t+="\n";q(z,C+1)}else{if(y==="score"||y==="o"){z=p.prettyScore(z)+" ("+z+")"}if(y==="w"||y==="w_c"||y==="size"||y==="gzip"||y==="cr"||y==="cs"){z=p.kbSize(z)+" ("+z+" bytes)"}t+=" "+p.decodeURIComponent(z)+"\n"}}}}};q(s,0);return t},testResults:function(w,q){var A,F,p,x,C,r,B,D,t=[],z={a:90,b:80,c:70,d:60,e:50,f:0,"n/a":-1},E=YSLOW,o=E.util,y=o.isObject(q),v=E.doc.rules,s=function(H){var I=parseInt(H,10);if(isNaN(I)&&typeof H==="string"){I=z[H.toLowerCase()]}if(I===0){return 0}return I||A||z.b},u=function(H){if(r){return r}if(!y){r=s(q);return r}else{if(q.hasOwnProperty(H)){return s(q[H])}else{return A||z.b}}},G=function(L,J,H,I,M){var K=v.hasOwnProperty(H)&&v[H].name;t.push({ok:L>=J,score:L,grade:o.prettyScore(L),name:H,description:K||"",message:I,offenders:M})};A=u("overall");G(w.o,A,"overall score");x=w.g;if(x){for(p in x){if(x.hasOwnProperty(p)){F=x[p];C=F.score;if(typeof C==="undefined"){C=-1}G(C,u(p),p,F.message,F.components)}}}return t},formatAsTAP:function(q){var r,w,y,t,p,o,u=q.length,v=[],s=YSLOW.util,x=s.decodeURIComponent;v.push("TAP version 13");v.push("1.."+u);for(r=0;r<u;r+=1){w=q[r];y=w.ok||w.score<0?"ok":"not ok";y+=" "+(r+1)+" "+w.grade+" ("+w.score+") "+w.name;if(w.description){y+=": "+w.description}if(w.score<0){y+=" # SKIP score N/A"}v.push(y);if(w.message){v.push(" ---");v.push(" message: "+w.message)}t=w.offenders;if(t){o=t.length;if(o>0){if(!w.message){v.push(" ---")}v.push(" offenders:");for(p=0;p<o;p+=1){v.push(' - "'+x(t[p])+'"')}}}if(w.message||o>0){v.push(" ...")}}return v.join("\n")},formatAsJUnit:function(s){var t,z,D,v,r,p,w=s.length,y=0,o=0,x=[],C=[],u=YSLOW.util,A=u.decodeURIComponent,B=u.safeXML,q=function(E){return E.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};for(t=0;t<w;t+=1){z=s[t];D=' <testcase name="'+q(z.name+(z.description?": "+z.description:""))+'"';D+=' status="'+z.grade+" ("+z.score+")";if(z.ok){C.push(D+'"/>')}else{o+=1;C.push(D+'">');if(z.score<0){y+=1;C.push(" <skipped>score N/A</skipped>")}D=" <failure";if(z.message){D+=' message="'+q(z.message)+'"'}v=z.offenders;if(v){C.push(D+">");p=v.length;for(r=0;r<p;r+=1){C.push(" "+B(A(v[r])))}C.push(" </failure>")}else{C.push(D+"/>")}C.push(" </testcase>")}}x.push('<?xml version="1.0" encoding="UTF-8" ?>');x.push("<testsuites>");D=' <testsuite name="YSlow" tests="'+w+'"';if(o){D+=' failures="'+o+'"'}if(y){D+=' skipped="'+y+'"'}D+=">";x.push(D);x=x.concat(C);x.push(" </testsuite>");x.push("</testsuites>");return x.join("\n")},getPageSpaceid:function(y){var x,t,u,s,p,r,q,w,v=/^\d+$/,o=y.getComponentsByType("doc");if(o[0]&&typeof o[0].body==="string"&&o[0].body.length>0){x=o[0].body;t=["%2fE%3d","/S=","SpaceID=","?f="," sid="];u=["%2fR%3d",":"," ","&"," "];for(s=0;s<t.length;s+=1){p=t[s];if(-1!==x.indexOf(p)){r=x.indexOf(p)+p.length;q=x.indexOf(u[s],r);if(-1!==q&&(q-r)<15){w=x.substring(r,q);if(v.test(w)){return w}}}}}return""},loadCSS:function(o,p){var q;if(!p){YSLOW.util.dump("YSLOW.util.loadCSS: doc is not specified");return""}q=p.createElement("link");q.rel="stylesheet";q.type="text/css";q.href=o;p.body.appendChild(q);return q},openLink:function(o){if(YSLOW.util.Preference.getPref("browser.link.open_external")===3){gBrowser.selectedTab=gBrowser.addTab(o)}else{window.open(o," blank")}},smushIt:function(q,t){var s,o=this.getSmushUrl(),p=o+"/ws.php?img="+encodeURIComponent(q),r=YSLOW.util.getXHR();r.open("GET",p,true);r.onreadystatechange=function(u){s=(u?u.target:r);if(s.readyState===4){t(JSON.parse(s.responseText))}};r.send(null)},getSmushUrl:function(){var o="http://www.smushit.com/ysmush.it";return YSLOW.util.Preference.getPref("smushItURL",o)+"/"},getNewDoc:function(){var p=null,o=new XMLHttpRequest();getBrowser().selectedTab=getBrowser().addTab("about:blank");p=window;o.open("get","about:blank",false);o.overrideMimeType("text/html");o.send(null);return p.content.document},makeAbsoluteUrl:function(o,p){var s,r,q,t;if(typeof o==="string"&&p){s=p.indexOf("://");t=p.slice(0,4);if(o.indexOf("://")<0&&(t==="http"||t==="file")){if(o.slice(0,1)==="/"){r=p.indexOf("/",s+3);if(r>-1){o=p.slice(0,r)+o}else{o=p+o}}else{q=p.lastIndexOf("/");if(q>s+3){o=p.slice(0,q+1)+o}else{o=p+"/"+o}}}}return o},preventDefault:function(o){if(typeof o.preventDefault==="function"){o.preventDefault()}else{o.returnValue=false}},trim:function(o){try{return(o&&o.trim)?o.trim():o.replace(/^\s+|\s+$/g,"")}catch(p){return o}},addEventListener:function(q,r,p){var o=YSLOW.util;if(q.addEventListener){o.addEventListener=function(t,u,s){t.addEventListener(u,s,false)}}else{if(q.attachEvent){o.addEventListener=function(t,u,s){t.attachEvent("on"+u,s)}}else{o.addEventListener=function(t,u,s){t["on"+u]=s}}}o.addEventListener(q,r,p)},removeEventListener:function(q,r,p){var o=YSLOW.util;if(q.removeEventListener){o.removeEventListener=function(t,u,s){t.removeEventListener(u,s,false)}}else{if(q.detachEvent){o.removeEventListener=function(t,u,s){t.detachEvent("on"+u,s)}}else{o.removeEventListener=function(t,u,s){delete t["on"+u]}}}o.removeEventListener(q,r,p)},getCurrentTarget:function(o){return o.currentTarget||o.srcElement},getTarget:function(o){return o.target||o.srcElement},getInlineTags:function(t,r,p){var s,o,q=function(A,w,v){var y,u,x,z,B=[];if(!A){return B}x=A.getElementsByTagName(w);for(y=0,u=x.length;y<u;y+=1){z=x[y];if(!z.src){B.push({contentNode:v,body:z.innerHTML})}}return B};r=r||(t&&t.getElementsByTagName("head")[0]);p=p||(t&&t.getElementsByTagName("body")[0]);s=q(r,"style","head");s=s.concat(q(p,"style","body"));o=q(r,"script","head");o=o.concat(q(p,"script","body"));return{styles:s,scripts:o}},countDOMElements:function(o){return(o&&o.getElementsByTagName("*").length)||0},getDocCookies:function(o){return(o&&o.cookie)||""},setInjected:function(y,r,w){var u,x,t,s,o,v,z,q,p={};if(!w){return r}if(typeof y.createElement==="function"){q=y.createElement("div");q.innerHTML=w}else{q=y}t=q.getElementsByTagName("script");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.src||s.getAttribute("src");if(o){p[o]={defer:s.defer||s.getAttribute("defer"),async:s.async||s.getAttribute("async")}}}t=q.getElementsByTagName("link");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.href||s.getAttribute("href");if(o&&(s.rel==="stylesheet"||s.type==="text/css")){p[o]=1}}t=q.getElementsByTagName("iframe");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.src||s.getAttribute("src");if(o){p[o]=1}}t=q.getElementsByTagName("embed");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.src||s.getAttribute("src");if(o){p[o]=1}}t=q.getElementsByTagName("param");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.value||s.getAttribute("value");if(o){p[o]=1}}t=q.getElementsByTagName("img");for(u=0,x=t.length;u<x;u+=1){s=t[u];o=s.src||s.getAttribute("src");if(o){p[o]=1}}for(u=0,x=r.length;u<x;u+=1){v=r[u];if(v.type==="js"||v.type==="css"||v.type==="flash"||v.type==="flash"||v.type==="image"){z=p[v.url];v.injected=!z;if(v.type==="js"&&z){v.defer=z.defer;v.async=z.async}}}return r},setTimer:function(p,o){setTimeout(p,o)}};YSLOW.util.event={subscribers:{},addListener:function(o,s,q){var p=this.subscribers,r=p[o];if(!r){r=p[o]=[]}r.push({callback:s,that:q})},removeListener:function(p,s){var q,r=this.subscribers[p],o=(r&&r.length)||0;for(q=0;q<o;q+=1){if(r[q].callback===s){r.splice(q,1);return true}}return false},fire:function(r,s){var o,p;if(typeof this.subscribers[r]==="undefined"){return false}for(o=0;o<this.subscribers[r].length;o+=1){p=this.subscribers[r][o];try{p.callback.call(p.that,s)}catch(q){}}return true}};YSLOW.util.Preference={nativePref:null,registerNative:function(p){this.nativePref=p},getPref:function(p,o){if(this.nativePref){return this.nativePref.getPref(p,o)}return o},getPrefList:function(p,o){if(this.nativePref){return this.nativePref.getPrefList(p,o)}return o},setPref:function(o,p){if(this.nativePref){this.nativePref.setPref(o,p)}},deletePref:function(o){if(this.nativePref){this.nativePref.deletePref(o)}}};YSLOW.doc={tools_desc:undefined,view_names:{},splash:{},rules:{},tools:{},components_legend:{},addRuleInfo:function(q,o,p){if(typeof q==="string"&&typeof o==="string"&&typeof p==="string"){this.rules[q]={name:o,info:p}}},addToolInfo:function(q,o,p){if(typeof q==="string"&&typeof o==="string"&&typeof p==="string"){this.tools[q]={name:o,info:p}}}};YSLOW.doc.addRuleInfo("ynumreq","Make fewer HTTP requests","Decreasing the number of components on a page reduces the number of HTTP requests required to render the page, resulting in faster page loads. Some ways to reduce the number of components include: combine files, combine multiple scripts into one script, combine multiple CSS files into one style sheet, and use CSS Sprites and image maps.");YSLOW.doc.addRuleInfo("ycdn","Use a Content Delivery Network (CDN)","User proximity to web servers impacts response times. Deploying content across multiple geographically dispersed servers helps users perceive that pages are loading faster.");YSLOW.doc.addRuleInfo("yexpires","Add Expires headers","Web pages are becoming increasingly complex with more scripts, style sheets, images, and Flash on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets, and Flash.");YSLOW.doc.addRuleInfo("ycompress","Compress components with gzip","Compression reduces response times by reducing the size of the HTTP response. Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim to support gzip.");YSLOW.doc.addRuleInfo("ycsstop","Put CSS at top","Moving style sheets to the document HEAD element helps pages appear to load quicker since this allows pages to render progressively.");YSLOW.doc.addRuleInfo("yjsbottom","Put JavaScript at bottom","JavaScript scripts block parallel downloads; that is, when a script is downloading, the browser will not start any other downloads. To help the page load faster, move scripts to the bottom of the page if they are deferrable.");YSLOW.doc.addRuleInfo("yexpressions","Avoid CSS expressions","CSS expressions (supported in IE beginning with Version 5) are a powerful, and dangerous, way to dynamically set CSS properties. These expressions are evaluated frequently: when the page is rendered and resized, when the page is scrolled, and even when the user moves the mouse over the page. These frequent evaluations degrade the user experience.");YSLOW.doc.addRuleInfo("yexternal","Make JavaScript and CSS external","Using external JavaScript and CSS files generally produces faster pages because the files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded each time the HTML document is requested. This reduces the number of HTTP requests but increases the HTML document size. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the HTML document size is reduced without increasing the number of HTTP requests.");YSLOW.doc.addRuleInfo("ydns","Reduce DNS lookups","The Domain Name System (DNS) maps hostnames to IP addresses, just like phonebooks map people's names to their phone numbers. When you type URL www.yahoo.com into the browser, the browser contacts a DNS resolver that returns the server's IP address. DNS has a cost; typically it takes 20 to 120 milliseconds for it to look up the IP address for a hostname. The browser cannot download anything from the host until the lookup completes.");YSLOW.doc.addRuleInfo("yminify","Minify JavaScript and CSS","Minification removes unnecessary characters from a file to reduce its size, thereby improving load times. When a file is minified, comments and unneeded white space characters (space, newline, and tab) are removed. This improves response time since the size of the download files is reduced.");YSLOW.doc.addRuleInfo("yredirects","Avoid URL redirects","URL redirects are made using HTTP status codes 301 and 302. They tell the browser to go to another location. Inserting a redirect between the user and the final HTML document delays everything on the page since nothing on the page can be rendered and no components can be downloaded until the HTML document arrives.");YSLOW.doc.addRuleInfo("ydupes","Remove duplicate JavaScript and CSS","Duplicate JavaScript and CSS files hurt performance by creating unnecessary HTTP requests (IE only) and wasted JavaScript execution (IE and Firefox). In IE, if an external script is included twice and is not cacheable, it generates two HTTP requests during page loading. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page. In both IE and Firefox, duplicate JavaScript scripts cause wasted time evaluating the same scripts more than once. This redundant script execution happens regardless of whether the script is cacheable.");YSLOW.doc.addRuleInfo("yetags","Configure entity tags (ETags)","Entity tags (ETags) are a mechanism web servers and the browser use to determine whether a component in the browser's cache matches one on the origin server. Since ETags are typically constructed using attributes that make them unique to a specific server hosting a site, the tags will not match when a browser gets the original component from one server and later tries to validate that component on a different server.");YSLOW.doc.addRuleInfo("yxhr","Make AJAX cacheable","One of AJAX's benefits is it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server. However, using AJAX does not guarantee the user will not wait for the asynchronous JavaScript and XML responses to return. Optimizing AJAX responses is important to improve performance, and making the responses cacheable is the best way to optimize them.");YSLOW.doc.addRuleInfo("yxhrmethod","Use GET for AJAX requests","When using the XMLHttpRequest object, the browser implements POST in two steps: (1) send the headers, and (2) send the data. It is better to use GET instead of POST since GET sends the headers and the data together (unless there are many cookies). IE's maximum URL length is 2 KB, so if you are sending more than this amount of data you may not be able to use GET.");YSLOW.doc.addRuleInfo("ymindom","Reduce the number of DOM elements","A complex page means more bytes to download, and it also means slower DOM access in JavaScript. Reduce the number of DOM elements on the page to improve performance.");YSLOW.doc.addRuleInfo("yno404","Avoid HTTP 404 (Not Found) error",'Making an HTTP request and receiving a 404 (Not Found) error is expensive and degrades the user experience.