Hand Crafted Software

 

The Difference between Static and Dynamic Web Pages

All the pages that make up the World Wide Web can be divided into two broad categories: static and dynamic. A static page, as the name suggests, is exactly the same every time that someone accesses it. The only way that a static page will ever change is if the text itself is either manually edited by someone, or if a new page is created that overwrites the original.

A static page is held on a Web Server in the form of a file containing text with HTML markup. When you request that page (by typing the URL of that page into your browser, or by clicking on a hyperlink that links to that page) the web server simply sends that file to your computer. Your web browser then reads the file and processes the HTML tags to modify the output in such a way that it is displayed in an appropriate format on your computer screen.

A dynamic page, on the other hand, is created afresh every single time that a client requests it; and correspondingly the content of the page might change considerably each time that it is requested. A simple example of a dynamic page is the output from a search engine, in which the user enters one or more keywords into an HTML form and then the server returns a list of items from a database that match those keywords. As a web site designer cannot anticipate all the possible searches that may be requested, there is no way that a static page would be able to fulfill the requirement.

Another more complex example of a dynamic page would be a page provided by a stockbroker to allow you to view a listing of your stock portfolio. The page will probably include (as an absolute minimum) the names of the stocks in the portfolio, the number of each stock held, and the current price of those stocks - all of which are pieces of information that will need to be accessed from a database, or (in the case of live stock prices) probably downloaded from another computer. The portfolio page also need to calculate the total value of each stock held and the total value of the portfolio, and these calculations too will have to be carried out dynamically every time the page is requested.

Naturally, the web page designer must ensure a that a customer can only see his own portfolio and not anyone else's, so additional programming will need to be incorporated into the system generating the page to provide security and user authorisation. A dynamic system will also need to be able to detect errors (such as if the database cannot provide the information that the user has requested) and then act appropriately. All this is well beyond the scope of standard HTML.

There are two basic ways to create a dynamic web page. One is to write a small program - perhaps in a conventional programming language like C or in a scripting language like Perl - that the server runs whenever it receives a request for the dynamic page in question. The program will operate independently of the server software, interface with the other services that it needs to create to page and finally output a text string containing all the text and HTML markup that the browser needs to format the page. The server simply takes this string and sends it back to your browser, which then interprets the string in exactly the same way as it would with any other HTML file it receives. This is the principle behind Java servelets - the 'servelet' being a small program written in Java that is then compiled and run by the server as required.

The other way to create a dynamic web page is to create an HTML file as normal, but embed special tags into the file that the server has been specifically programmed to deal with. The server (generally through subsidiary "add-on" modules) does all the necessary processing and replaces the special tags with strings of HTML marked-up text that can then be interpreted and displayed by the browser in the usual way.

This second method is often the preferred technique for pages which are primarily static and contain just a few minor dynamic elements, as the static elements in the page can then be maintained using conventional web page editors. This is how a host of proprietary and open source technologies cope with the problem of generating dynamic web pages - many of these technologies being identified by dreaded three letter acronyms such as ASP, JSP and PHP. The proprietary web server Cold Fusion also uses this method.

Which of the two methods is best depends very much on what job you are trying to achieve. Very often results can be quickly obtained using a scripting language such as PHP, but the resulting code is likely to have all the drawbacks of an interpreted language, such as being slow to run. This does mean, however, that PHP can be useful for prototyping a web site that can later be re-written in a more robust form using (for example) Java servelets.

 
Back Home

© 2003 Richard Young. All rights reserved.