I am using google maps and returning html/lat/long from my MySQL databaseCurrentlyA user picks a business category e.g; Video Production.an ajax call is sent to a CodeIgniter controllerthe Controller then queries the db, and returns the following data via JSONLat/Long of the markerHTML for the popup windowthis is approximately 34 rows in the database across two tables per businessthe ajax call receives this data and then plots the marker along with the html onto the mapThe data that is returned from the controller is one big json object... This is done for all businesses that exist in the Video Production category (currently approx 40 businesses). As you can see, pulling this data for multiple categories (100s of businesses) can get very very taxing on the server.My question isWould it be more beneficial to modify the process flow as such:a user picks a business category e.g; Video Production.an ajax call is sent to a CodeIgniter controllerthe controller then queries the database for the location base informationlat/longlevel (used to change marker icon color)This would be a single row per business with several columnsthe ajax call receives this data and then plots the marker on the mapwhen the user clicks a marker an ajax call is sent to a CodeIgniter Controllerthe controller queries the database for the HTML and additional data based on business_idand if not, what are some better suggestions to this problem?In summary this means rather than including the HTML and additional data along for each business, only submitting minimal location information and then re-query for that information when each business marker is clicked.Potential Downsideslonger load times when a user clicks a marker iconmore code??more queries to the database
Which would be a better way to load data via ajax
php;sql;ajax;theory
Unless you notice that this is causing some sort of performance issue, I would leave as is.  Generally, network round trips are the slowest item, and should be minimized as much as possible.  I would only worry about such an optimization once you get to the point where there is an observable performance issue.  Without profiling, it is impossible to tell which method will be truly faster, and it could be different for each user.  JSON is a fairly terse format,  and a lot of stuff can be condensed.Also, if you do find that performance is an issue, you might want to look into client side templating (such as KnockoutJS, jQuery templates, Handlebars, Mustache, ...) for the popup window, assuming that the content is based off of a template.  This may allow you to minimize the data sent.