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


Groups > comp.lang.javascript > #37891

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

From Martin Leese <please@see.Web.for.e-mail.INVALID>
Newsgroups comp.lang.javascript
Subject Re: Embed <script> at end of HTML vs. DOMContentLoaded handler
Date 2019-11-12 21:55 -0700
Organization A noiseless patient Spider
Message-ID <qqg2cl$7q1$1@dont-email.me> (permalink)
References <c9de2141-a12e-4496-91e9-47809298f77b@googlegroups.com>

Show all headers | View raw


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?
> 
> A priori, I think the HTML looks much tidier if all the scripts
> and links are at the top. But the javascript possibly looks 
> tidier if it doesn't need to delay the mainline code by wrapping
> it in an event handler.
> 
> Are there other considerations I've overlooked or better ways
> to make this choice?

You can use include the "defer" attribute,
to defer execution, but only if you use the
"src" attribute.  That is to say, if your
script is not embedded.

-- 
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

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