This Forum has been archived

Forums: Admin Central Index General Questions Some curiosities about Javascript
Wikia's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.

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?
$(document).ready(function() {});
$(function() {});

 Cafeinlove msg 2012/7/5, 05:37 (KST), 20:37 (UTC)

  1. 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.
  2. If not wrapped in a conditional, yes.
  3. Yes, the latter is a shorthand for the former AFAIK.
 TK999 20:52, July 4, 2012 (UTC)
3) Yes. TK is right. Rappy 20:55, July 4, 2012 (UTC)
  1. That depends a little on your definition of "much". How many lines of code are you talking about? 100? 1000? 10000? More?
  2. 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 <script> 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.
--  pecoes  21:00, July 04, 2012 (UTC) 
@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.
  1. I don't know how many lines they will do, but how about 50kbyte in optimized version?
  2. I see that. I've already tried <verbatim> for a twitter widget, but I didn't know what this was for. I'll think about verbatim my scripts. Thank you.
 Cafeinlove msg 2012/7/5, 06:11 (KST), 21:11 (UTC)
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? --  pecoes  21:29, July 04, 2012 (UTC) 
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.  Cafeinlove msg 2012/7/5, 06:51 (KST), 21:51 (UTC)

(Reset indent) 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. --  pecoes  22:14, July 04, 2012 (UTC) 

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.  Cafeinlove msg 2012/7/5, 07:47 (KST), 22:47 (UTC)