Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #37776

Re: Embed <script> at end of HTML vs. DOMContentLoaded handler

Path csiph.com!weretis.net!feeder6.news.weretis.net!feeder7.news.weretis.net!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.javascript
Subject Re: Embed <script> at end of HTML vs. DOMContentLoaded handler
Date Thu, 14 Nov 2019 16:25:55 +0100
Lines 33
Message-ID <h35a03FolrU1@mid.individual.net> (permalink)
References <c9de2141-a12e-4496-91e9-47809298f77b@googlegroups.com> <1ad170ed-9717-4be9-8fab-79a9d56766a5@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace individual.net wWebnjCEmO7shV1cNtoOaQ5jyySQDbqHGc5jOAy2Xjmb9wajcE
Cancel-Lock sha1:pBLEtyAXNqVdnO5mQkjVXL/+n1w=
In-Reply-To <1ad170ed-9717-4be9-8fab-79a9d56766a5@googlegroups.com>
Xref csiph.com comp.lang.javascript:37776

Show key headers only | View raw


Julio Di Egidio:

> On Wednesday, 13 November 2019 00:52:45 UTC+1, luserdroog  wrote:
>>
>> I've noticed a lot of pages put the <script> tags at the end
>> of the HTML file. Does this practice avoid the need to put
>> DOM-manipulating code in a handler for DOMContentLoaded?
> 
> Loading scripts at the bottom makes the page render faster, because (deferred
> scripts aside) the very parsing of the page is synchronous and will pause in
> order to load and run any scripts it encounters (though the browser starts
> showing things along the way, which is why the perceived responsiveness is
[...]

Some nitpicking here:

The total rendering time itself will not change. So if a page needs 2
seconds to render, this won't change. But the rendering will start with
less delay if there are no scripts at the top or included in the header.

So for example instead of heaving 0.3 seconds script execution followed
by 2 seconds page rendering you will have 2 seconds page rendering and
0.3 seconds script execution when the rendering has finished.

On the other hand even a page which looks to be fully loaded may still
need some time to execute the scripts at the bottom before you can fully
interact with it. However this is not a problem in most cases since
visitors will usually spend at least half a second or more to read the
content of the page before they try to interact with elements.

-- 
Arno Welzel
https://arnowelzel.de

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Embed <script> at end of HTML vs. DOMContentLoaded handler luserdroog <luser.droog@gmail.com> - 2019-11-12 15:52 -0800
  Re: Embed <script> at end of HTML vs. DOMContentLoaded handler Arno Welzel <usenet@arnowelzel.de> - 2019-11-14 16:25 +0100
    Re: Embed <script> at end of HTML vs. DOMContentLoaded handler Julio Di Egidio <julio@diegidio.name> - 2019-11-14 08:34 -0800
      Re: Embed <script> at end of HTML vs. DOMContentLoaded handler Arno Welzel <usenet@arnowelzel.de> - 2019-11-15 17:29 +0100
    Re: Embed <script> at end of HTML vs. DOMContentLoaded handler John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-14 19:30 +0000
  Re: Embed <script> at end of HTML vs. DOMContentLoaded handler Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-11-12 21:55 -0700
  Re: Embed <script> at end of HTML vs. DOMContentLoaded handler Julio Di Egidio <julio@diegidio.name> - 2019-11-13 07:18 -0800

csiph-web