Using deferred execution using Javascript

Does anyone use lazy JavaScript execution or is it something from the past? (I do not see this being used on major websites). Also, what are the pros and cons of placing your javascript in the title tag and placing it in the body?

thanks

+3
source share
3 answers

Placing JavaScript in the main tag can slow down page loading time, as JS needs to be parsed, processed, and executed (and possibly loaded if they are external files) before rendering the DOM. Even the use of "defer" does not actually allow this to be avoided - some browsers ignore the directive, and those that pay attention do not fully implement it, as you expected.

Placing JS at the bottom of the page is a great way to get quick wins with obvious page load times, and it also encourages proper SoC and progressive improvement, making it a little harder to encode incorrectly.

+4
source

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

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

, HTML 4, , onload, , , , .

+2

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

+1
source

Source: https://habr.com/ru/post/1706365/


All Articles