What is the difference between placing an event listener in an HTML tag with a BODY tag?

I looked at google.com source and saw:
<!doctype html><html onmousemove="google&&google.fade&&google.fade(event)">

I did not know that the HTML tag can accept event listeners. What is the difference between placing an event listener in an HTML tag with a BODY tag? Is there a difference in the event bubble?

+6
javascript html javascript-events
source share
1 answer

I saw this a couple of days ago and did not think about it. But one of the reasons may be "performance", as is always the case with Google :)

For a very slow client, the <html> will be processed first, and the onmousemove handler will be ready to fire if the user moves the mouse. If there is too much content inside the <head> , this may be preferable, since it may take some time for onclick on <body> to register, since you must first load and analyze the entire contents of the header.

In fact, this is already happening, there are approximately 2KB content before <body> appears.

+1
source share

All Articles