0

I've noticed on websites like IGN and Gamespot that their feature article and review pages are HTML (.html) with dynamic content like user comments included on the page.

How do they include this type of dynamic content in a static HTML page?

If I turn Javascript off and view one of their pages, they dynamic content disappears so I assume it's done with Javascript.

I'm interested in serving similar content and would like to do it via HTML instead of a dynamic PHP page with everything stored in a database (except for stuff like comments).

Hope that makes sense.

Tom
  • 4,467
  • 17
  • 59
  • 91
  • 1
    Note that the fact that a URL ends with .html doesn't mean the page is static. It's very easy to configure a web server to associate *.html with PHP, a Java Servlet, or any other dynamic page generation technology. – JB Nizet Mar 26 '11 at 20:07

4 Answers4

2

It's done with Javascript. The most common way to do this is to have Javascript on the page that accesses some sort of API that retrieves the appropriate comments (aka AJAX). You won't be able to access a database this way unless you expose that database using some kind of API (probably HTTP).

If you want something like this on your own site, look in to services like Disqus which store comments on their servers and retrieve them using Javascript.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
1

One commonly used technique to achieve this is to use AJAX. Obviously the dynamic content must come from a dynamic server side script.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

I don't know, but I'm guessing it's JavaScript ajax. There are a few solutions that could do this, but JavaScript is the best, check out MooTools (my personal favourite) and JQuery.

mrdnk
  • 656
  • 9
  • 24
1

When you have the client-server relationship, there are often many things happening in the background.

For instance, Apache can be configured to parse any "file extension" with file ending .xxx as PHP. So, you can configure your Apache instance to parse PHP within .html files just as it would with .php files:

http://www.electrictoolbox.com/apache-parse-html-as-php/

And as well, you can serve different "content-types" to the browser, so that a PHP-parsed page can send, for instance, PDF content to the browser:

http://php.net/manual/en/function.header.php

Now, a possibly easier way is to use Apache's rewrite to take a URL request and rewrite it to a PHP page with the rest of the URL request being added as request attributes, such as in the Model-View-Controller pattern:

http://expressionengine.com/wiki/Remove_index.php_From_URLs/

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

So that a URL such as http://www.example.com/article/feature/my_story.html will actually be seen by the server's PHP parser as http://www.example.com/index.php?class=article&method=feature&id=my_story.html

And then you can use AJAX methods to specifically update a portion of a page, as has been mentioned in other answers.

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
  • Seems like having Apache treat parse PHP in .html pages is the way to go for me. Any downside to it? Can I restrict this behavior to certain directories? I think using this approach, editors can post HTML articles that have the commenting system in PHP at the bottom. – Tom Mar 26 '11 at 20:32
  • I don't see anything wrong with it, per se. If that's what you need and you have the means to make it happen, then make it happen. Consider whether you need it or not, though, since you could easily bypass that with something like Expression Engine and weblog entries that end in .html. The file extensions, to many degrees, are meaningless when you get to the client/server manipulation layer. – Jared Farrish Mar 26 '11 at 20:38
  • @Tom, reading your comment again, I would highly suggest going with something like Expression Engine or Drupal instead of a custom system. If you need a commenting system and you have editors/story writers, you don't need to reinvent a CMS, you just need one that does what you have required, and EE would be a good solution, although you would need to buy it (I am not affiliated with EllisLab, although I have one site that uses EE: http://emergency.unt.edu/). – Jared Farrish Mar 26 '11 at 20:45
  • I will check out EE. Seems like that's what IGN uses. I was going to store every article detail item in a table then construct the page based on the items traditionally like .php?articleid=10 but it seems like EE does all this for you and is highly customizable. – Tom Mar 26 '11 at 21:23
  • @Tom - EE is very useful for your use case (as is Drupal). Unless you live off the challenge, go with a supported solution. This is a very well known problem in web publishing. – Jared Farrish Mar 26 '11 at 21:25
  • Yeah, I just wish they offered a demo. You have to buy it before being able to try it. – Tom Mar 26 '11 at 21:36
  • @Tom - Contact Leslie Camacho or Lisa Wess - Most likely, if you're serious about using the system, they'd accommodate you testing it out first. I found them very reasonable (although at the time they did have the Community version). – Jared Farrish Mar 26 '11 at 21:39