Topic: To optimise javscript file includes (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: you tell me |
posted 04-16-2008 09:13
Hi guys, I was just going over my project and noticed something that for some weird reason shouldn't be but unfortunately it is. I don't know why but anyway - I've created and included dozens of javascript files for use in my prpoject. Almost all of them are handlers for ajax calls and validation checks etc. However I noticed that on average in every page in my projject I'm including like an average of 15 to 20 javascript files. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 04-16-2008 09:49
indeed - having a bunch of javascript is going to be a burden - each file is often one roundtrip to the server (provided it correctly returns '304, not modified'). On the other hand, including javascript you don't need isn't great either. Guess it depends on how often you actually switch pages in your application. |
Paranoid (IV) Inmate From: Norway |
posted 04-16-2008 09:53
Version the scripts and set a loooong expiry date on them. The browser should not poke the server to see if the file changed until the expiry date. Another thing is to merge some files together to decrease the number of connections : browsers are slowly increasing the number of connections per domain but many are still limited to 2 and with 15-20 JS files, plus CSS plus images, you quickly hit the wall. |
Bipolar (III) Inmate From: you tell me |
posted 04-16-2008 12:24
Now that you mentioned it - I have been finding the scriptaculous library a tad wee bit - uh big and missing out a lot of effects for which I seem to end up downloading patches or standalone js code. What other alternatives are there for scriptaculous that have ALL the effects and more plus come with less overheads... |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 04-16-2008 13:47
the Dojo toolkit is seriously engineered... but then, switching after your project has started could be a bit of a drag... |
Bipolar (III) Inmate From: you tell me |
posted 04-16-2008 14:55
Well the thing is that because my project is using a lot of code form different places - it slows down alot so I'm thinking of how to optimise it in whatever way possible. The Db end is fine - no isues there however what I've noticed is that I've included a loty of self standing mini project sinside my project. |
Paranoid (IV) Inmate From: Norway |
posted 04-16-2008 15:05
Have you looked at Yahoo's Exceptional Performance stuff ? Lots of sound advices. Steve Souders & co. did quite a few talks on performance. |
Paranoid (IV) Inmate From: Umeå, Sweden |
posted 04-17-2008 01:15
One problem with having many script files is that browsers halt parsing further into the HTML file until the file is downloaded completely, because the script may contain document.write calls. As an alternative behaviour, the browser could be parsing ahead but deferring further insertions into the document tree until the script has been executed instead of halting entirely. In this case, it could parallelise the requests but still demand strict order on the treebuilding. In any case, the result would be that you're putting a bigger block on incremental rendering than if you had used only a single or a smaller number of scripts. |
Paranoid (IV) Inmate From: Norway |
posted 04-17-2008 01:18 |
Bipolar (III) Inmate From: you tell me |
posted 04-19-2008 08:30
Hmmm sound advice but in this case wouldn't this be problematic in the situation that lets say I have a function call somewhere in the middle of the page and all the function sripts are included in the bottom? |
Paranoid (IV) Inmate From: Umeå, Sweden |
posted 04-19-2008 08:54
Paritycheck: Then don't do it that way. The script files should just declare and define those variables, functions and event handlers you need. The only script that should do any action is the last script on the page, or an event handler of the 'load' or 'DOMContentLoaded' types. If you avoid using document.write there's really no reason to do any work while the HTML is still being parsed. In fact, for loading speed reasons in ie, you should consider deferring the scripts. |