Re: Multiple JS Files or Single JS File
"John M. Hann" <[email protected]> Mon, 27 Mar 2006 14:10:21 -0000
| Newsgroups | gmane.comp.web.dom.wdf |
|---|---|
| Message-ID | <[email protected]> |
Hey Mandy, The size of your files are quite small. They're each downloaded in 4-5 IP packets. Even on dial-up, that's pretty fast. Because of pipelining in HTTP 1.1, these would go even faster (even though pipelining is set to a low number by default in most browsers). That said, one file will always download much faster than multiple files that aggregate to the same size. Another thing to keep in mind is that download time for static files is typically only a concern for the user's FIRST VISIT. Keeping your files small and separate is a GOOD THING if you plan to reuse these files as you mentioned. I say "keep doing it". However, if you do get concerned about download time, there are several things you can do: 1) Use ANT or your own custom scripts to assemble the combined js file when you check in your code to a source code control system. 2) Use ANT or your own custom scripts to assemble the combined js file when you deploy the files to the web server. 3) "Obfuscate" the js files (which compresses them). 4) Use the "defer" attribute in any script tags that don't need to be downloaded before rendering the page. (I've also seen people put the script tags after closing the body tag, but don't know if this has any compatibility implications (doubtful).) Regards, -- John Hann http://e-numera.com/ <http://e-numera.com/> http://ajax-web2.com/ <http://ajax-web2.com/> --- In [email protected], "Maninder, Singh" <mandiv@...> wrote: > > Hi Everyone, > > Just wanted to take some guidance on the following- > > In my AJAX appication I have a number of js files - > > 1. Some are library specific and hence in different js files. > 2. Some are application specific. > > In case of application specific files, the only reason why I separated the js content in 3-4 files is because it is easier to maintain & makes more sense to keep them separate. > For eg: Some functions are for easy manipulations & are generic so I moved them to utils.js, some are a hash of error messages so I moved them to errorMessages.js and so on. > > These 3-4 js files are not huge, they must be around 4-5KB or even less. But, they have been broken up because of the above reason. > > Now coming to my question - is this is a good thing to do or a bad thing? > > Pros (of having mulitple files) - > 1. Easier maintainence > 2. If code is updated in one file, we don't need to download the huge js (sigma of all js's) again > > Cons (of having multiple files) - > 1. Would the browser open 3-4 different connections for downloading them? > Since most of my userbase is on dialup, every connection could be costly as compared to only one connection in case of 1 huge js file. > > Well I have been referring to it as a huge js file but it won't actually be huge (wuld be around 30KB..but looks huge compared to 4-5KB :) > > Thoughts? > > Thank you, > Mandy. > [Non-text portions of this message have been removed] Unsubscribe [email protected] List info http://www.quirksmode.org/dom/list.html Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/wdf-dom/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/