Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Re: body tag

Expand Messages
  • Paul de Jong
    The issue I was referring to is that the body tag needs to be completely loaded before a DOM script runs, especially if you have something like
    Message 1 of 5 , Aug 4, 2008
    • 0 Attachment
      The issue I was referring to is that the body tag needs to be
      completely loaded before a DOM script runs, especially if you have
      something like document.body.appendChild in your script. Having the
      script in the body means one needs to do complicated DOM checking to
      make sure the body is loaded before the script runs...or at least set
      a arbitrary delay in the hopes that the end of the body will get
      processed in that time.

      It seems weird to put the script tag inside the body tag, when
      logically it should come after it. I was just wondering if there was
      some reason other then the one you stated.

      I have never encountered a problem putting the script tag after the
      body tag. Putting the script tags in the head is highly inefficient
      since it stops the page from loading and can cause a blank screen.
      (See Steve Souders book: High Performance Web Sites, O'Reilly, 2007)

      Thanks.

      On Mon, Aug 4, 2008 at 3:51 PM, Douglas Crockford <douglas@...> wrote:
      > --- In jslint_com@yahoogroups.com, "riderpaulpaul" <riderpaul@...> wrote:
      >>
      >> One big issue in JavaScript is the onload issue. Many of the
      >> frameworks have a periodic check to see if the body has loaded using
      >> various methods.
      >>
      >> Since script tags can be in the HTML head (outside the HTML body), why
      >> can't one simply place the initiating script tag between [/body] and
      >> [/html]. It seems to me like this solves a lot of problems.
      >> Semantically it also make sense to place the tag there, rather then in
      >> the body that is being manipulated by the script.
      >>
      >> [html]
      >> [head][/head]
      >> [body][/body]
      >> [script][/script]
      >> [/html]
      >
      > I don't see how it solves anything. There is a lot in the HTML
      > recommendations that doesn't make sense, but the requirement that the
      > tags all go either into the head or the body seems pretty reasonable.
      >
      >
    • Andy Stevens
      ... Not always, I have inline scripts that work just fine so long as the parts of the DOM they are manipulating are ready & available. ... Seems reasonable to
      Message 2 of 5 , Aug 5, 2008
      • 0 Attachment
        2008/8/5 Paul de Jong <riderpaul@...>:
        > The issue I was referring to is that the body tag needs to be
        > completely loaded before a DOM script runs,

        Not always, I have inline scripts that work just fine so long as the
        parts of the DOM they are manipulating are ready & available.

        > especially if you have
        > something like document.body.appendChild in your script.

        Seems reasonable to me that the body should be complete before you add to it.

        > Having the
        > script in the body means one needs to do complicated DOM checking to
        > make sure the body is loaded before the script runs...or at least set
        > a arbitrary delay in the hopes that the end of the body will get
        > processed in that time.

        How complicated is <body
        onload="finished_loading_so_call_the_script_now()"> anyway?

        > It seems weird to put the script tag inside the body tag, when
        > logically it should come after it. I was just wondering if there was
        > some reason other then the one you stated.
        >
        > I have never encountered a problem putting the script tag after the
        > body tag.

        Hey, if it works for you then go for it. So long as you don't care
        about your HTML being invalid according to the DTD, so it may break
        unexpectedly in future browser versions. If you care so much, you can
        also join the HTML 5 discussions and try to get it added to the spec.

        What does any of this have to do with JSLint, though? Are you saying
        that your inline script isn't being checked if it's not inside the
        head or body tags?


        Andy.
      • Paul de Jong
        The issue with onload is that it is not ondomload, so if any file being downloaded takes too long the script does not fire and the user could be interacting
        Message 3 of 5 , Aug 5, 2008
        • 0 Attachment
          The issue with onload is that it is not ondomload, so if any file
          being downloaded takes too long the script does not fire and the user
          could be interacting even before the script loads.

          The two main reasons for me asking the question here are: 1) I just
          read "JavaScript: The Good Parts, Douglas Crockford, O'Reilly" and
          think it is the best JavaScript book I have ever read. It does avoid
          DOM issues entirely though, and I was hoping to get an informed
          opinion on this topic. I work on image heavy sites and onload is not
          an option. 2) I used JSLint and it told me that putting the script tag
          below the body was bad and I was wondering why. I was wondering if it
          was just a convention to put the script tag(s) in the head and body or
          if it was an actual rule.

          I will make a suggestion for the HTML 5 group. I think a footer block
          that was guaranteed to run just after the DOM is fully loaded would be
          great.

          Thank you for your responses!

          On Tue, Aug 5, 2008 at 5:08 AM, Andy Stevens
          <insomniacpenguin@...> wrote:
          > 2008/8/5 Paul de Jong <riderpaul@...>:
          >
          >> The issue I was referring to is that the body tag needs to be
          >> completely loaded before a DOM script runs,
          >
          > Not always, I have inline scripts that work just fine so long as the
          > parts of the DOM they are manipulating are ready & available.
          >
          >> especially if you have
          >> something like document.body.appendChild in your script.
          >
          > Seems reasonable to me that the body should be complete before you add to
          > it.
          >
          >> Having the
          >> script in the body means one needs to do complicated DOM checking to
          >> make sure the body is loaded before the script runs...or at least set
          >> a arbitrary delay in the hopes that the end of the body will get
          >> processed in that time.
          >
          > How complicated is <body
          > onload="finished_loading_so_call_the_script_now()"> anyway?
          >
          >> It seems weird to put the script tag inside the body tag, when
          >> logically it should come after it. I was just wondering if there was
          >> some reason other then the one you stated.
          >>
          >> I have never encountered a problem putting the script tag after the
          >> body tag.
          >
          > Hey, if it works for you then go for it. So long as you don't care
          > about your HTML being invalid according to the DTD, so it may break
          > unexpectedly in future browser versions. If you care so much, you can
          > also join the HTML 5 discussions and try to get it added to the spec.
          >
          > What does any of this have to do with JSLint, though? Are you saying
          > that your inline script isn't being checked if it's not inside the
          > head or body tags?
          >
          > Andy.
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.