Question

I have a Google Maps page that I am looking to optimize as it is heavily used. Currently, the user does the following to search:

  1. Types an address, and clicks submit.
  2. This page submits the address as post data to another page (map.php).
  3. map.php is loaded, and javascript is executed to display the map.
  4. This javascript submits a request to the webserver based on the searched location, retrieves an xml file, and displays the results on the map.

The xml file request can take a signficant amount of time (a few seconds) due to external factors (api). I am hoping to request this xml file before the page has fully loaded to speed up the request. Unfortunately, this request uses a callback that has not been defined until an external asset has been loaded.

What is the best way for me to prefetch the xml file, and setup a callback for a function that has not been loaded yet? Basically, I want to load the xml file at the top of the page, and wait to call the callback function until it has been retrieved.

Was it helpful?

Solution

You can define your own callback function, then use that to call the other callback function provided it exists:

if (typeof theCallback == 'function') 
  theCallback(arg1, arg2, arg3, etc); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top