22 Şubat 2011 Salı

Loading time improvements with Javascript

This is another tidbit for coders.
(To be honest, I'm just finding enough time to do some finishing touches for my drafts which are gathering dust and post them here!)

We come up with new hacks, invariably with a javascript file attached. You add all the hacks, end up with a truckload of javascript includes and thus, a longer loading time.

THE ROOT CAUSE
The real problem is the sequential nature of XHTML. XHTML is parsed a tag at a time. So, if you have a couple of lines like this:



the files are loaded as follows:
The parser first encounters the first script tag. It then slowly retrieves script1.js and loads it into memory, which takes a lot of time. The parser thinks this is the best time to take a nap and doesn't proceed to parse the next script tag until the current download of script1.js is finished.

Hiç yorum yok:

Yorum Gönder