PDA

View Full Version : What are the drawbacks of using Javascript?



purifier
12-14-2006, 07:48 AM
I've heard many people say that there are disadvantages of using multiple javascripts on a single page. Is that true? I mean can I have two scripts main11.js and main2.js run on the same page or is there some kind of restriction?

One more question is: Does too much of Javascript spoil the fun?

jscheuer1
12-14-2006, 08:28 AM
Javascript is a bit like images. Too many scripts and the page is overloaded, takes too long to load on many systems, that sort of thing. In addition, more than one script on a page can conflict for various reasons causing one, the other or both scripts not to work. These conflicts can almost always be worked out but, even then it can sometimes be quite a complex task to do so. Another drawback to javascript is that some folks may not be using it so, it really shouldn't be an essential part of the page. This last bit isn't so important these days as the vast majority of folks are using javascript. Prudent design can and should provide fall backs for non-javascript enabled browsers.

purifier
12-14-2006, 08:36 AM
Thank You Sir. So conflicts in the sense, global and local variable conflicts? And suppose that I include a js file in the html of a page. Is it fetched even before it is required or will it be fetched after an event is triggered? I mean if i wrote something like <script src="main.js"> will main.js be fectched before there is a function reference?

jscheuer1
12-14-2006, 08:39 AM
Global variables, yes. Functions, objects and elements too.

All scripts on or linked to a page are loaded as the page loads, even if they are never used on the page. However, once an external script is loaded, it is cached so, will not need to be loaded for other pages that it is linked to, at least until it is removed from the cache.

purifier
12-14-2006, 08:48 AM
Oh.. so maybe that is the reason a website takes time when loading for the first time and then speeds up... Thank You Sir...

BLiZZaRD
12-14-2006, 09:41 AM
I had a JS clock on my main page. just a tiny 4 line code. My main page took 12 to 22 seconds to display. I removed that single script, and my page now loads in 1 to 2 seconds.

Servers are weird. ROTF