For various reasons, I’m considering using DHTML to display some data on my database-driven website. I’m curious for opinions as to a particular architecture.
I would like a set of data to be loaded from the database when a visitor accesses the page (the page is PHP/mySQL). Then, if the user would like to display a different set of data, they would click on a button that, instead of reloading the page, would remotely call a PHP script that would dynamically replace the data on the page with a new set.
My main motivation for this method (outside of it being kind of cool) is to cut down the number of pageviews counted on my site, and to cut down on the number of advertising impressions served. Plus, this ancillary data may not be interesting to everyone, so I’d rather not serve it up on the initial page if I don’t have to, to cut down bandwidth.
The drawback I can see is that if the user wants to see the original set of data, they have to click a button which then must query the database again to reload it via DHTML vs. the original PHP script load. Once each DHTML data set has been loaded, since they are cached, no further database queries are performed.
The reason I don’t want to do the initial load via DHTML (which would cut down one query to the database) is because search engines will not see the content on the page. That means that I may see some extra server usage due to this style of implementation. I could get around this by augmenting the data on the page instead of replacing it.
And of course, I could always just create a new PHP script that displays this data, meaning that a new page would be loaded if someone wanted to see the new data.
And one issue I run into is a quote issue. Since I want to use the same script to generate the initial content plus the DHTML content (to avoid multiple development), and since I build a javascript variable with that content, if I have a single quote (‘) in the content, it breaks the script. I’m sure there must be a workaround (simply escaping quotes may not work because that might break the original script). I’m also forced to eliminate all carriage returns in the content, since this also breaks the creation of the javascript variable.
I’m curious to see if people think that the DHTML method would either increase server load or decrease it. Perhaps a consideration is that in order to use the same script to generate the content both ways, I have to break my driving script up into several sub-scripts pieces that are “included” into the main script, and which can then be included into the DHTML in pieces. So every time the main script is called, I have several include’s in that script. I’m not sure if that would consume more resources than a single script. (I’m trying not to overload my server).
Another consideration is multiple connections to the database. The script that populates the javascript variable using DHTML must make its own connection to the database whenever it needs data, independent from the original PHP script. I don’t know if that’s good or bad.
I’d appreciate any thoughts on this, and here’s an example of what I’m trying to do:
[url]http://www.hockeydb.com/test/stats/pdisplay.php3?pid=1644
The “list cards” button is an example of the script way of displaying data, and the “show trades” button is an example of the DHTML.
Thanks,
Ralph