Reputation: 1
As I learn more and more about JQuery & PHP requests, a couple things have occured to me.
I've designed a web page with a bunch of empty DIVs that are populate by Ajax calls during and after this page loads. So far, in order for this page to load, I make a total of 8 (.get()) calls using JQuery/Ajax to php pages, get the results and populate this divs.
A. Make 8 Ajax calls to 8 different PHP pages or... B. Make 1 Ajax call to 1 PHP page that generates the content of all previous 8 together?
Can any of you give some pointers on light-weight and efficient developing guidelines?
Upvotes: 1
Views: 82
Reputation: 4778
You should try to minimize your AJAX calls on page load. In a perfect world, the only AJAX calls being made would be due to user interaction AFTER the document has loaded. This means you should code your backend in a way that assembles and displays the entire page content initially.
On a side note, it's a good idea to make AJAX sites backwards compatible. Something in your PHP like:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
if(!IS_AJAX) { require_once("header.php"); }
echo "this is ajax content";
if(!IS_AJAX) { require_once("footerer.php"); }
This will detect whether or not it was an ajax request, and if not display the header and footer for normal operation.
Upvotes: 2