- Build a php file return only the information we need.
- Parse PHP output directly to the network just send the necessary information.
The first case is optimal in terms of traffic load and generates only the necessary information and generates no extra query to the database, it has one drawback: the maintenance, any change in the application logic should be done in duplicate in the conventional web script that sends the AJAX part. And this is a problem especially in large applications. The second case, that solves this problem and based on the same code and with the passage of a variable get, PHP only returns the necessary contended eliminating unnecessary traffic. If we use some form of caching PHP output, as in our case, we eliminate the extra queries to compose the rest of the page that we will not need. Penalize only the memory and CPU load required for server parsing of XHTML. We opted for the second option and for this we use http://simplehtmldom.sourceforge.net/ a tool that allows us to work with the DOM in a similar way as we do with JQuery. In our PHP just have to add the following lines:
- ) . load ( "nuestraPagina.php?selector=#seccionACargar" ) ; $ ("# SeccionACargar.") Load ("nuestraPagina.php? Selector = # seccionACargar");
Thus nuestraPagina.php loading? Selector = # seccionACargar the php will not return all the HTML of the page if not we will return only the content of saving a good candidad selector byte (or Kb) in the transmission of data. As I said this is a huge savings over the alternative offered jquery
- ) . load ( "nuestraPagina.php #seccionACargar" ) ; $ ("# SeccionACargar.") Load ("nuestraPagina.php # seccionACargar");
Jquery recovered since the entire page and then it parses. We have successfully used this technique in www.berroguetto.com to load each of the sections of the website, and item of them, like news and each of the pages of the pagers.