0

This is about calling the initialize function for the Google Maps API. I would prefer to call it at the end of the HTML instead of putting it in the body onload. It appears to be working, but is there anything wrong with this approach?

The Google API code I am referring to can be viewed at Place Autocomplete Address Form.


This is not a duplicate of window.onload vs <body onload=""/>.

Or this closed one, Unobtrusive JavaScript onload function.

It is closest to this one: Initializing JS components at the end of HTML or on "onload"?

However, my question is not generic.

Community
  • 1
  • 1
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41

1 Answers1

2

That's just personal preference. Both ways work fine. They probably used the onload handler because it appears to be more foolproof.

If the code was at the end of the file, some people might copy it and happily edit around without fully understanding why it is written at the end of the file and then later on shoot out a bunch of posts asking why their code isn't working.

Sebastian Nette
  • 7,364
  • 2
  • 17
  • 17