/    Sign up×
Community /Pin to ProfileBookmark

Architecture question: DHTML or not?

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[/url]

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonFeb 26.2004 — What you could do is just include ALL the content on one page but break it up with div tags and give those div tags systematic id's. Then with DHTML only show parts of it at a time (noscript browsers would see it all).

This would cut right down on the number of requests to the server and so should avoid overloading it.

The only way I know to escape a single quote is to put a in front of it. If this causes problems with your PHP then isn't there some way to escape a ?
×

Success!

Help @Ralph_Slate spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...