Max Posted May 25, 2012 Share Posted May 25, 2012 Anothe philosophical question for Larry and all wiser and more knowledgable than I.... I took Larry's advice and had a look at Google's front page to see how they used JS to autocomplete the search criteria - you know, when you put 'AA' in the search window - before pressing the search button, it gives you 'aaron', 'aaliyah' etc. but oddly, not Aardvaark! but I digress. What I got was a huge block of compressed code that was obviously generated by a server side language. Here is a SMALL section: function ob(a,{var c=jb,d=lb,g;g=34>=a?a<=Z.w?a==Z.u||a==Z.v||a==Z.z?i:e:a>=Z.k&&a<=Z.o?e:i:200<=a?e:i;g&&(c=kb,d=mb);if(d){d=encodeURIComponent;c=["//www.google.com/gen_204?atyp=i&zx=",(new Date).getTime(),"&oge=",a,"&ogex=",d("37102"),"&ogf=",j.bv.f,"&ogp=",d("1"),"&ogsr=",Math.round(1/c),"&ogv=",d("1337744543.1337808325"),"&ogd=",d("es"),"&ogl=",d("es")];if({"ogw"in b&&(c.push("&ogw="+b.ogw),delete b.ogw);var f;g=b;var h=[];for(f in g)0!=h.length&&h.push(","),h.push(f),h.push("."),h.push(g[f]);f=h.join("");""!=f&&(c.push("&ogad="),c.push(d(f)))}sa(c.join(""))}}I=ob;n("il",I,J);var pb={};r.il=pb;var qb=function(a,b,c,d,g,f,h,m,k,q){v(function(){j.paa(a,b,c,d,g,f,h,m,k,q)})},rb=function(){v(function(){j.prm()})},sb=function(a){v(function(){j.spn(a)})},tb=function(a){v(function(){j.sps(a)})},ub=function(a){v(function(){j.spp(a)})},vb={"27":"//ssl.gstatic.com/gb/images/silhouette_27.png","27":"//ssl.gstatic.com/gb/images/silhouette_27.png","27":"//ssl.gstatic.com/gb/images/silhouette_27.png"},wb=function(a){return(a=vb[a])||"//ssl.gstatic.com/gb/images/silhouette_27.png"},xb=function(){v(function(){j.spd()})};n("spn",sb);n("spp",ub);n("sps",tb);n("spd",xb);n("paa",qb);n("prm",rb);Ta("gbd4",rb);if(l.a("")){var yb={g:l.a(""),d:l.a(""),e:"",sanw:l.a(""),m:"",p:"//ssl.gstatic.com/gb/images/silhouette_96.png",xp:l.a("1"),mg:"%1$s (delegada)",md:"%1$s (predeterminada)",mh:"276",s:"1",pp:wb,ppl:l.a(""),ppa:l.a("1"),ppm:"Página de Google+"};r.prf=yb};if(l.a("1")&&l.a("1")){var $=function(a){Y(function(){u("pw",a);A("pw")})};n("lPW",$);s.push(["pw", The question is - is the future of JS that it will all one day be generated by a WYSIWYG processor that will take all of the fun out of coding??? Link to comment Share on other sites More sharing options...
Larry Posted May 25, 2012 Share Posted May 25, 2012 Hey Max. I wouldn't assume that's server generated. I don't know how Google does their thing, but that just looks to me like minimized code. So you do normal JavaScript programming, and when it's working as you want it, you minimize it to make it a smaller download. Link to comment Share on other sites More sharing options...
HartleySan Posted May 26, 2012 Share Posted May 26, 2012 Max, Larry is right, that code has definitely been minified. My favorite minifier is the YUI one. An online version is available from the following link: http://refresh-sf.com/yui/ Link to comment Share on other sites More sharing options...
Max Posted May 26, 2012 Author Share Posted May 26, 2012 Thanks...but that begs two questions - 1: Is there a 'maxifier'? to bring it back. 2: Included in the code (not shown in my example) is CSS and JS and as far as I know other scripts embedded in the HTML. Far beit for me to tell Google how to do their jobs but............they DO make Chrome! Wouldn't it be easier (and industry compliant) if they followed the first chapters of Larry's book and put the CSS and JS in separate files???? Link to comment Share on other sites More sharing options...
HartleySan Posted May 26, 2012 Share Posted May 26, 2012 1) There is no "maxifier", which is why you must always save a separate copy of your code to easily make changes at a later time. 2) I've always wondered about this myself! As we all know, when CSS and JS are placed in separate files, they're cached separately, making it possible to load the page faster. Of course, then again, that's assuming that the CSS and JS hardly ever change and the HTML changes a lot (which is the case with most sites). Perhaps in Google's case though, it's the exact opposite. If it were that the CSS and JS change a lot, but the HTML hardly ever changes, then maybe having everything in one file is quicker. To be honest, I really don't know the answer to this question, and I'd love to know. I can only assume that, being Google, they have extensively tested all possible permutations, and found that having everything in one file is the fastest method when you're dealing with literally millions of requests every second of every day. Max, I'll look into question #2 some more and see if I can't find a better answer. In the meantime, maybe Larry can shed some light on things. Link to comment Share on other sites More sharing options...
Larry Posted May 26, 2012 Share Posted May 26, 2012 I don't have a great answer here, except that I trust Google knows something we don't. But, on the other hand, this may be a regional thing. Looking at Google now, I'm seeing separate, external CSS and JS files. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 26, 2012 Share Posted May 26, 2012 1) There is no "maxifier", which is why you must always save a separate copy of your code to easily make changes at a later time. Why? It shouldn't be a problem coding one. Maybe we got a business idea here. Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2012 Share Posted May 27, 2012 Hmmm...maybe it is regional. I'm in Japan, and all the CSS and JS is in the HTML file and minified. As for a maxifer, Antonio, I suppose it's not beyond the realm of possibilities, but the variables would still be screwed up, regardless. Still, if you were trying to figure out what some minified code was doing, a maxifier might help. Link to comment Share on other sites More sharing options...
Max Posted May 27, 2012 Author Share Posted May 27, 2012 Yes, I am sure that Google know what they are doing (well....they have a lot more money than me!...so must be getting something right). On the subject of server generated code, I would suggest that the Google server is generating the JS (as we would in php) as the list of strings that appear on the entry of characters must change (I guess) with the statistics of searches. i.e. if lots of people are looking up 'euro crisis' then the characters e - u would bring that up from JS. Just guessing here. Link to comment Share on other sites More sharing options...
HartleySan Posted May 27, 2012 Share Posted May 27, 2012 Are you talking about the Google home page or a search results page? I can't comment on the code for search results pages because I've never looked at it. In trying to find an answer the other day, I happened upon the following link, which was pretty interesting: http://code.google.com/edu/submissions/html-css-javascript/ What's particularly interesting is that in their JS intro video, they explicitly state that linking to an external JS file is best, which makes me wonder. I wonder if there's any way to contact Google and ask... Link to comment Share on other sites More sharing options...
Max Posted May 28, 2012 Author Share Posted May 28, 2012 The web site I got the code from is http://www.google.es/. On another subject, I find Google quite irritating as it assumes, as I am in Spain, that I want to do a Spanish search. I can call www.google.com, www.google.co.uk, or whatever but it still reverts to Spanish searches. Even going into advanced search mode doesn't really fix it, so if I am looking solely for British sites, I use www.yahoo.co.uk. I will not comment on the press story today!!!........ http://www.dailymail.co.uk/debate/index.html Link to comment Share on other sites More sharing options...
HartleySan Posted May 29, 2012 Share Posted May 29, 2012 Google automatically gives me Google Japan because I live in Japan, but there is always a link on the site to switch to the standard Google. The browser remembers the setting as well. Not sure if that's an option for you. Link to comment Share on other sites More sharing options...
Max Posted May 29, 2012 Author Share Posted May 29, 2012 Hi HartleySan Had a good look - can't find that option. Easier to use Yahoo.co.uk. Link to comment Share on other sites More sharing options...
HartleySan Posted May 29, 2012 Share Posted May 29, 2012 Don't blame ya. I guess Google Japan and Google Spain are just two different beasts. Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 1, 2012 Share Posted June 1, 2012 Hmmm...maybe it is regional. I'm in Japan, and all the CSS and JS is in the HTML file and minified. As for a maxifer, Antonio, I suppose it's not beyond the realm of possibilities, but the variables would still be screwed up, regardless. Still, if you were trying to figure out what some minified code was doing, a maxifier might help. It was more of a joke, but it really should not be that hard. After building a simple Code validator, I can assure you it's fully possible. All you have to do is look at one char at the time, line by line, and interpret the code. Link to comment Share on other sites More sharing options...
HartleySan Posted June 1, 2012 Share Posted June 1, 2012 All joking aside, a maxifer might be really helpful. I wonder if anyone has made one yet. You feel like working on one together, Antonio? Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 2, 2012 Share Posted June 2, 2012 Sounds like a fun project. Yes, I'm in. Link to comment Share on other sites More sharing options...
marvinds Posted December 4, 2013 Share Posted December 4, 2013 So how did the maximizer project go? As a beginning javascript programmer, it does sound like an interesting project Link to comment Share on other sites More sharing options...
HartleySan Posted December 4, 2013 Share Posted December 4, 2013 Never bothered with it. There are plenty out there though, including one that's now built into Chrome. If you load a JS file from the Resources tab in Chrome DevTools, and then click the "{ }" button, you can prettify (i.e., maxify) the code. As stated in the thread though, the variable names will not be restored to their original value, but at least the code is spaced out and easier to read. Link to comment Share on other sites More sharing options...
Recommended Posts