|Title:||Static vs Dynamic Output|
|Date:||July 10th, 2001|
There is a trend lately, especially in web development, towards creating dynamic output.
This trend is silly.
First, some definitions for clarity:
Static output means that it has already been generated before (and
separate) from being viewed.
Dynamic output is generated each time it is viewed.
A simple example of this would be an online photo album. The album changes whenever photos are added (or removed..), and the output is viewed when someone goes to the web site with their browser.
Such a photo album can be generated statically, so that sections of the album are regenerated whenever photos are added, or they can be generated dynamically, such as through a CGI that generates the album output everytime it is viewed.
Now, there are many examples of people using dynamic output, but is it a good idea? There are certainly cases where it is necessary, such as when the data is changing on a regular basis, or when it isn't changing under human power, such as those clock web pages that were so popular when the web was an infant.
Fortunately we don't see many silly web clocks anymore.
Generating output takes computing power. Dynamic output makes more sense initially - someone wants to see something, so you create it for them. Static output requires a rethinking of this process, of unrolling the loop, in a sense, so that generation is separate from viewing. And which technique should we use?
It's a pretty simple decision, actually, and it's unfortunately often ignored. Remember:
static means output is generated when it changes
dynamic means output is generated when it is viewed
So you have to ask yourself two questions:
Consider a few examples:
In this case, it often does make more sense to use dynamic code (though not if the page is viewed more often than the clock changes!). To use static, you would need to setup some sort of regular job that writes a web page on a regular basis (question #2 above).
More importantly, I would ask you - why do you want a clock on your web page?
Adding photos is a process, whether it is a human downloading some of their latest trip photos, or a webcam saving a new image after a delay.
Regardless, you could add the album creation to the end of this process, and then your photo album will be static and up to date.
More importantly, this would generally save CPU time. If not, I have to ask you why you are updating your photo album more often than people are looking at it?