On Mon, Nov 7, 2011 at 2:10 PM, Timothy J. Warren <timw4m...@gmail.com> wrote:
>
> Unless your page loads really slowly, I've found that the Javascript delay
> is almost non-existent.
>

It mostly depends on the size of the loaded Javascript and what it
does when executed.

In case of scripts used for tracking/logging it is advisable to load
them as soon as possible (in the head section).

If the Javascript takes time to execute (DOM manipulations or XHR
requests) that time will be added to the total time before the "load"
event is dispatched. The "defer" attribute helps deferring the
execution to happen after the "load" event thus preventing execution
time to sum up to the page load time.

Having the script loaded "asynchronously", in parallel to page
loading, is faster in most circumstance.


--
Diego


> On Monday, November 7, 2011 8:06:57 AM UTC-5, Lasse Reichstein wrote:
>>
>> The defer attribute tells the browser that the script doesn't have to
>> be run immediately (i.e., it doesn't use document.write). That means
>> that it can start fetching the script immediately when it sees the
>> script tag *and* continue parsing the document.
>>
>> Without the defer attribute, the browser must stop parsing the
>> document until the script has completed loading and been run, because
>> the script might use document.write to change how the parsing should
>> continue.
>>
>> If you put the script at the end of the body, the browser won't start
>> fetching it until it has parsed the script tag. That introduces an
>> extra delay before the script is ready and run - the time it takes to
>> parse the document and create the DOM for it.
>>
>> By putting the script tag early but with the defer attribute can
>> reduce the latency of your page - the time it takes before the onload
>> event fires - by fetching over the network (or even from local cache),
>> which is I/O bound, while it parses the document (which is memory/CPU
>> bound).
>>
>> But then, AFAIK, not all browsers handle the defer attribute the way
>> it was intended, so it's no panacea.
>>
>> /L
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to