Ramshankar
on software & life

Static vs Dynamic websites

There are varying descriptions of static and dynamic sites on the internet. Sometimes they are used to describe technical details of how a server processes content, while other times they are used to describe the nature of the content being served. There are techniques that blur the lines between dynamic and static sites but that’s not the focus of this article.

This article gives a broad outline of static and dynamic sites and some of their typical pros and cons. It’s not meant to be an exhaustive guide that covers every technical detail.

Static website

A static site serves pre-made content, exactly as stored on the server, to all its users. There are three key aspects to qualify the website as static:

  1. “pre-made”: the content has been created beforehand. It is not generated at the time the user’s browser requests content.

  2. “as stored on the server”: the content isn’t transformed at the time the server handles the request. HTML, CSS, JavaScript, images, fonts and other resources are retrieved as files rather than from a database or other sources.

  3. “all its users”: the content sent to every user of the site is identical.

The content therefore is static HTML pages. The pages may also include code like JavaScript, but the code has no means of interacting with the server.⁠[1]

Logical content communication diagram of static website
Communication with a static site
The diagram above represents logical communication. It does not represent physical bytes transferred between the client (user) and the server.

The content on the server is static and is identical to every user of the site. Think of it as a restaurant that only offers one dish and won’t allow a customer to change their order once they’ve been served. The chef simply prepares and serves the meal as soon as the customer makes an order. Every customer receives the same dish.

Dynamic website

A dynamic site serves content generated on-demand, based on the user’s request. The content can include remote scripts that modify the HTML page on the user’s browser.

Logical diagram of dynamic website
Communication with a dynamic site

This allows the content to be personalized for each user. For example, a server that provides search results for a user’s query. Using the restaurant analogy, it would be a restaurant that allows its customers to change their order half way through their meal. Or one that serves different dishes depending on who the customer is.

Choosing between a dynamic and static website

The more decisive you are with your requirements and constraints for your site early on, the easier it is to decide if you should go with a static or a dynamic site. If, after a month of deploying your static site, you need a feature that’s only possible with a dynamic site, it’s going to involve a lot of work that could’ve been avoided. Take into consideration your current requirements and foresee, as much as you can, features that you may want in the future.

Before creating this site, I had a clear vision on what I wanted and what my constraints were. There were a few features that I wasn’t quite sure if I would need, but they were relatively minor features that I was willing to forego. Despite a lot of planning, it can at times be a difficult decision to choose. Here are some pros and cons of static and dynamic sites which may be of help to you.

A comparison of static and dynamic sites
Static website Dynamic website

Simpler to secure.
Static sites don’t run server-side software like PHP that are subject to security breaches.

Harder to secure.
Although it’s possible to create secure dynamic sites, it requires work to make it secure.

Limited functionality.
Features like user logins are not possible. Even features like a commenting system for a blog can be difficult to set up and often crippled in some way.

Full functionality.
Interactive features are possible including serving personalized content. Popular CMS offers easy to setup features like commenting system, automatic indexing and searching of content etc.

Offers finer control.
Since pages are not generated but statically served, it’s possible to finely control content of each page if required.

Offers better uniformity.
Most CMS use templates that provide uniformity and offer some degree of flexibility. However, it can be quite difficult to intricately control every aspect of individual pages.

Ideal for smaller sites.
Static sites are file based. Making changes may involve re-generating the entire site which could scale poorly as your site grows.

Works for larger sites.
Dynamic sites often use a database. Making changes involves updating the database rather than regenerating content. Databases are fast at handling large volumes of data and are built to scale.

Fast? Slow? Maybe.
Content isn’t generated on-demand so time is saved when the user requests content. However, static sites loses out on optimizations that could be done based on the user.

Fast? Slow? Maybe.
Making a dynamic site fast is certainly possible, but involves complex caching techniques. They also have the option of optimizing content based on the user’s request. Blanket statements like “static sites are faster” isn’t always true.

How to choose a static or dynamic site
Requirement Description Decision

Interactivity

You require users to interact with web applications.

Dynamic

User logins

You require users to be able to login to your site (e.g, for a shopping cart, user profiles etc.)

Dynamic

Blog

If you require features like comments and search, it’s easier with a dynamic site. For a simple blog, choose a static site.

Static or dynamic

Resumés or personal sites

A site for showcasing your resumé or personal page.

Static


1. The code could request new content, like requesting a new page, but cannot dynamically interact with the server.