3

Does anyone use deferred execution of JavaScript or is it something from the past? (I don't see it used on major websites). Also, what are the pros and cons of placing your javascript in the head tag vs placing it in the body?

Thanks

1
  • It was only implemented for use with document.write() Commented Apr 14, 2009 at 8:10

3 Answers 3

4

Placing JavaScript in the head tag can slow down the load time of the page, since the JS has to be parsed, processed and executed (and possibly downloaded, if they are external files) before the DOM is rendered. Even using "defer" doesn't really avoid this - some browsers ignore the directive and the ones which do pay attention don't fully implement it as you'd expect.

Placing JS at the foot of the page is a great way to get some quick wins with apparent page load time, and also encourages proper SoC and progressive enhancement by making it a little harder to code improperly.

Sign up to request clarification or add additional context in comments.

Comments

2

http://www.websiteoptimization.com/speed/tweak/defer/

For all those who want to know more about deferred execution.

It seems that this is a feature of HTML 4, so not necessarily from the past, but with the onload event doing pretty much what the deferred option asks, I'm not sure there's a huge demand for it.

1 Comment

Actually I visited the same link before I ask this question, but thanks anyway :)
1

The big con is that it's implemented incredibly differently between browsers. Basically, you really just can't use it as it seems to be intended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.