Admin Forum:Some curiosities about Javascript

I always ask myself next questions, if somebody can answer one of them, please reply me.
 * 1) Unless there's no conflict between scrpits, can I put as much script as I want? (I mean by much, 3~5 times as much than most of wikia sites, for example.)
 * 2) Some scripts that I'm using is destinated to affect only elements on the main page. Are these scripts loaded on every article load? I'm afraid they make the site slow or so.
 * 3) Does the following two codes do same thing on wikia sites?


 * Theoretically yes, but generally JS libraries like jQuery consume more memory on the user part. You could compare the performances of alternatives (built–in DOM handler vs. jQuery vs. something else) on websites like jsPerf.
 * If not wrapped in a conditional, yes.
 * Yes, the latter is a shorthand for the former AFAIK.
 * 20:52, July 4, 2012 (UTC)


 * 3) Yes. TK is right. Rappy 20:55, July 4, 2012 (UTC)


 * That depends a little on your definition of "much". How many lines of code are you talking about? 100? 1000? 10000? More?
 * If they're in your MediaWiki:Common.js then yes. If you put your homepage's code into a separate file in the MediaWiki namespace and surround it with &lt;script&gt; tags, then you could verbatim it into the main page. The verbatim tag is undocumented, but you can see it in action on this wiki's main page.


 * @TK-999 and Rappy -- Thank you. And then, can I use head.js to speed up the page loading? I'm not sure whether this kind of things are supported by wikia.
 * @Pecoes
 * I don't know how many lines they will do, but how about 50kbyte in optimized version?
 * I see that. I've already tried &lt;verbatim&gt; for a twitter widget, but I didn't know what this was for. I'll think about verbatim my scripts. Thank you.


 * 50K is larger than jQuery and exactly as large as jQuery UI. In other words: Its' an awful lot. What library are you loading and are you absolutely sure you need it? --


 * I don't have any details for the moment, because I just wanted to know if I have a size limit for Javascript (and how much it is), like template limit of MediaWiki, and I answered with a size calculated roughly. Actually I'm adding lots of JS code (but it still isn't so big at all), and this makes me to devote attention to its disavantage.

There is no way the MediaWiki software could impose a size limit on your JS code. In that sense you're perfectly safe. It's the load-time of your page you should be worried about. Browsers are funny about JS. When they encounter JS they drop everything else and download and parse the JS first. That's the pitfall. --


 * Indeed. I'm keeping in mind that more I use JS (mostly complex ones) more the site risks slowing down and encountering problems.. Though knowing our sites' capacity draws curiosity.