Monday, 23 July 2012

Web Development Concepts: Static Versus Dynamic

What is the difference between a static and dynamic Web page?

Essentially, whether a Web page is static or dynamic depends on what happens between the user making a request to see it, and the server sending the requested content to their browser. It makes no difference to users whether a page is static or dynamic, but is relevant to developers, as each model uses different techniques and technologies.

Essentially a static page is one whose content is stored in static, unchanging form in a document on the Web server, while the content of a dynamic page is only created when it is requested for viewing.

What happens when someone browses to a page?

When you browse to a Web page, for example by clicking a link or typing its URL into your browser address bar, your computer sends a request message to the Web server on which the requested page is hosted.

With a static page, the content is simply sitting in a file, typically in HTML, and the content of this file is returned by the server to your computer, where it is displayed in your browser window. For example, if you had a file saved as "page.html" on your server in the root directory, and browsed to it as follows:

http://exampledomain.com/page.html

The server would respond by sending the content of the file.

For dynamic pages, the process is different. Dynamic pages use programming languages such as PHP. In this case you would save your script on the server, for example using the name "page.php", and it would contain programming code as well as HTML code.

When the page is browsed to this time:

http://exampledomain.com/page.php

The code within the script file is executed (run) on the server. The server side program may do many different things, but typically one of them will be to build a Web page with HTML content and send this to the user's browser. The browser displays this HTML the same way it would have if the page had been static - the difference lies in what happens on the server, and makes no difference at the user (or "client") end.

How exactly is this different?

Static and dynamic pages don't just use different file formats, they use a fundamentally different technique. Static pages typically contain only markup code, whereas dynamic pages also contain programming code.

The content of an HTML file is basically text, images etc contained within a tree structure, with each element delineated by tags, each pair of opening and closing tags comprising an element as in the following example paragraph:

Some text...


This is HTML markup, and its structure, together with formatting such as CSS, tells the browser how the content of each element should be laid out and displayed.

With a dynamic page containing server side code, a different process takes place. The page script is executed according to its own logical structure, and as it goes it builds HTML structures and writes them out. This example PHP performs a simple calculation and writes the result out in HTML:

<?php
$answer=3*2;
echo "<p>".$answer."<p>";
?>

A typical PHP script will also do other things such as connecting to a database and querying it for data to write out as part of the HTML.

What are the advantages to using dynamic pages?

There are many advantages to using dynamic pages, the main one being the fact that they contain dynamic data. By connecting to a database, a dynamic page can potentially offer different content each time it is viewed. Static page content remains the same unless the page files themselves are manually changed, whereas dynamic pages populate their content at the time of viewing, according to what happens to be in the data store at that particular time.

It is often the case that many pages within a site will contain the same, or similar content. If this content needs to be changed, in a static site each page on which it occurs will need to be changed in turn. However, using dynamic scripting, the piece of content can be contained in a single, dedicated script, and this script can then be called from each page on which the content item appears. If the content needs to be changed, it only has to be changed in one place, i.e. the dedicated script, or the database if this is where it comes from.

Dynamic sites are therefore easier to maintain and to make changes to, while still keeping a consistent appearance and behaviour. If a site is being built for commercial purposes, being able to store the data in a database is also an advantage in itself.

Are there disadvantages to using dynamic pages?

The only potential disadvantage to using dynamic pages is the fact that a greater range of technologies, and therefore skills, are involved. A certain amount of programming expertise is necessary, and in most cases database development as well. However, if you're thinking about trying dynamic Web page development, don't be put off even if you have no programming experience, as these skills are actually relatively easy to pick up. There are lots of online tutorials and guides, so you really can teach yourself.

Do I need to use dynamic pages?


No! Using dynamic pages is not obligatory. However, depending on the purpose and nature of your site, it may be a real advantage. Setting your dynamic site up may seem an intimidating prospect, but once this is done the site will become much easier to amend and maintain. If your site only contains a small amount of simple information that does not need to be updated very often, there's probably no need to learn Web programming if it isn't something you're interested in.

How do I get started creating dynamic pages?

The first thing is to make sure you have a sound enough grasp of the basic Web technologies that are used in both static and dynamic pages, including the initial skills for making a Web page using HTML, CSS and JavaScript. You don't need to be at an advanced level, just make sure you understand the basic principles and practices.

Next is learning a server side language. I would recommend PHP, which is available on most Web hosting platforms. Start with the basics and build your knowledge incrementally, this is the only way to do it, and don't worry if you feel you're making slow progress, it will all fall into place eventually!

If you're building a dynamic site, you'll probably want to use a database. MySQL is available for free on many Web hosting packages and is a good system to start with. You can learn SQL if you like, but if your host provides phpMyAdmin, you can carry out most common tasks using the browser interface. If you're unsure about how to structure your database, it may be worth finding out a bit about relational database modelling.

Related Links
MySQL :: Developer Zone
MySQL Tutorial - Introduction
phpMyAdmin
PhpMyAdmin Tutorial
PHP: PHP Manual - Manual
PHP Tutorial
SQL Tutorial

Tech Interpreter Links:
Why Web Developers are Excited About HTML5 and CSS3
Using Scripts in HTML Pages
What is Web Content?
What is Dynamic Content?
Web Development Concepts: Client and Server
How to Get Started with Web Development

No comments:

Post a Comment