Google Maps API loading after page display

My landing page contains most of Google Maps, which slows down loading time. I am trying to do the following:

  • First load the static elements so that the page loads quickly.
  • Display a loading notification in the map placeholder so that the user knows that the map is approaching.
  • Download and map display

I have done this:

$(document).ready(function() {
  map_initialize();
}

The function map_initialize()loads the map into its div container. However, this still does not display static elements with a fist. The page will wait for completion map_initialize(), then load static elements simultaneously with the map.

+3
source share
3 answers

window.onload , :

. , DOM, .

: Mozilla Dev: window.onload

:

, , window.onload :

window.onload = map_initialize;
+4

:

$('body').load(function() {
  map_initialize();
});

[edit] jQuery: http://api.jquery.com/load-event/#comment-43474051

0

If you use the onLoad event, static elements should load before your map. The method readyin jQuery will be run before everything is loaded; it starts as soon as documentready.

0
source

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


All Articles