Forum Moderators: open

Message Too Old, No Replies

Large Javascript Files Slow?

         

benj0323

6:45 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



I develop quite a few websites and I wanted to put together a javascript file that contained all of my "Tools" per say. Common javascript functions that I would like to have when developing a website, kind of like my own library. Although some functions websites wont use.

So lets say this file is composed of 100 functions and I develop a website that only uses 2 of the functions. Would the javascript and website be significantly quicker if I had a javascript file with ONLY those 2 functions vs. 100 functions?

I wasnt sure if file size slowed down the website speed. I realize the client would have to download the file, but downloading a javascript file with 100 functions probably wouldnt take that long at all.

Thanks for your input.

JAB Creations

10:25 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm no JS expert but it sounds like what you're doing is similer to my PHP includes. I simply call one includes file for PHP and call a string to be printed. In JS case you're calling a function. From my limited perspective I could only imagine a solid yes that you could though I'm not sure how you would do it.

The way I would approach this is to use a bounch of functions that simply did a document.write ('function number 3') for example.

Then make a quick dummy page linked to your JS file and call the functions as you need. Preview the dummy page and it should list each of the function numbers as so. Thats how I'd approach seeing if the idea would work in the first place though again I'm still learning the syntax.

There are up and down sides to using a single js file. The upside is you save a few dosen or hundred (maybe even thousand) bytes from repeating JS includes in your HTML. The downside is if you mess up one script you may mess them ALL up.

What I would suggest then is to develope each script seperately. If you MUST test a live page, add a seperate includs and a seperate js file. Once you get it to work without any errors in target generations of Gecko, KHTML, MSIE, and Opera then add it to your master JS file and delete the temporary JS includes (if you're using a live page/site).

Hopefully someone could provide a bit more details on how exactly you could execute your idea though in an easy to replicate fashion? I am interested in this now that I think about it. :-) Best of luck!