Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:27:38+00:00 2026-05-15T15:27:38+00:00

Will the DOM definitely be ready if I place my jquery code right before

  • 0

Will the DOM definitely be ready if I place my jquery code right before the </body> tag?

I have some jquery code and when I put it in the $.ready() function I can see a flash of what the page looks like before the javascript code is run.

However, if I put the code right before the </body> tag then I only see what the page looks like after the javascript is run. I used timers to see the time difference, and the code put before the end of the </body> executed 300ms sooner than the code in $.ready.

EDIT:If the DOM is reliably ready when i call my code before the </body> tag, what is the benefit to putting my code in $.ready, considering that my javascript will execute sooner if I put it before </body>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:27:39+00:00Added an answer on May 15, 2026 at 3:27 pm

    Yes, the DOM is reliably ready at that point. This thread from the Google Closure Library mailing list may be of interest, although unfortunately as far as I know they haven’t followed up with an actual article. Some quotes from Erik Arvidsson from that thread:

    The short story is that we don’t want to wait for DOMContentReady (or worse
    the load event) since it leads to bad user experience.

    and (in relation to whether the DOM element immediately above a script element will really be there)

    The DOM node is there and if you query for its size or something else
    that requires a reflow a reflow will happen so that the layout data is
    up to date.

    Some further notes:

    • If you can, load your JavaScript file from a different (apparent) host than the images and such on your page (from a subdomain, or a static service, etc.); otherwise, even though you’re not waiting for a “load” event, your JavaScript file will still be at the end of the download queue. You may find that you get more flashing, rather than less, if it’s at the end of the queue and you’re waiting for it. (Remember that the HTTP 1.1 spec recommends downloading no more than two items from a given host simultaneously, and most browsers — and some servers — enforce that.)
    • Related to that, you might consider using a CDN service for your own script (and other resources, but be sure to spread them across different apparent host names).
    • The DOM will be ready, but (naturally) not all of your images and such will be.
    • You can minimize apparent flashing by setting the body’s background color to as closely match the dominant color of the resulting rendered page as possible, using CSS included in the page (to avoid a delay while your CSS is fetched).
    • For a publicly-facing website, if you can avoid relying on jQuery for the basic rendering of the page, that’s probably for the best, since not everyone will have JavaScript enabled. Of course, if your target audience is more StackOverflow-like, you’re probably on a winner assuming they will. 🙂
    • If you use jQuery from a CDN like Google’s Ajax Libraries stuff, the odds of your target user already having it loaded on their first visit to your site will improve, minimizing the delay before your code runs (e.g., while jQuery is being loaded).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

jquery- Definitely a great choice for DOM manipulation, and have lot of libraries. extjs
I have done some web based projects, but I don't think too much about
I've got portions of pages being replaced with HTML retrieved via AJAX calls. Some
Been using Javascript libraries like Prototype and jQuery for development, for a while now.
There is a web page with place holder (a normal div). Via ajax calls
I am writing a script at the moment that will grab certain information from
I'm currently in the process of developing a GWT 1.7.1 application that deals with
I'm planning an XML web service that takes an XML request and returns an
[edit]sigh... the spam protection here isn't letting me post the links, so I guess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.