Pros and cons of Going Static

Pros and cons of Going Static

It's funny how static sites are all the rage yet again. Back in the day, when I was taking my first steps in the IT world with a notepad window open, I was creating none other than static sites. However, over the years they became obsolete as various CMS systems took over and nobody wanted to hear the word "static" anymore.

Now, in the age of continuous remix of bygone times, going static was a matter of time. Is it pure nostalgia, or do static sites have benefits that can't be overlooked?

What are static sites?

Before we dive deeper and start looking at the pros and cons of static sites, let's explain what they are.

This diagram shows a decent overview of how they work:

Image loading...Overview of how static sites work

Here's how it goes:

  • The user enters a URL in the address bar of their browser.
  • The query is sent to the server.
  • The server parses PHP files.
  • At some point, the server queries the database to get... well, data.
  • The parsed files and data from the DB show up in the user's browser as a fully rendered HTML page.

You can see the problem with this flow right away: if the user repeatedly queries for the same thing, the server will parse the files and query the DB over and over again.

When our site gets more popular and attracts more users this can become a problem really quickly.

That's why at some point we're going to turn to different caching mechanisms. This changes the flow a bit:

Image loading...Static sites with caching mechanism

In this setup, the system checks if the user has already queried the server for the requested site. If not, the system serves it normally but creates a static version in parallel.

Thanks to that, each subsequent query for the same content returns the generated static site. As a result, only the initial request puts a strain on the system.

Now let's discuss what the flow looks like for static WordPress:

Image loading...Overview of how WordPress static sites work

First, the entire site is converted to HTML files. When this is done, the files are uploaded to a server.

This way, when users query the server for your site, they always get their content from static HTML files.

As a result, the production server doesn't need PHP or even a database.

Static WordPress - the benefits

Speed

Static sites don't have to be parsed by the server and they don't need to query the database with every incoming request. Thanks to that, the server can get the content to users much quicker.

There are some solid numbers behind these claims. In my experiments in which I tested the performance of WP Owls with loader.io, I got the following results with 5 clients running for 30 seconds each:

  • WordPress without caching - 2844 ms avg. response time
  • WordPress with caching - 345 ms avg. response time
  • Static WordPress - 16 ms avg. response time

As you can see, the static WordPress wins with a response time over 11 times faster than the WP site with caching enabled.

The results can - and will - differ depending on the server you use. I conducted my tests on a budget server, albeit one with SSH access.

Security

Another undisputable advantage of static WordPress is its security. It all comes down to these two aspects:

  • WordPress and its static version can live on separate servers. Thanks to that, you can secure the main WP to an extreme level. For example, you can completely cut it off from the internet. The best thing is that it won't affect the live site at all.

  • A static site is pure HTML, which eliminates most attack vectors caused by vulnerabilities in plugins, themes, or even core WP. The production site doesn't have an admin panel, so hackers can't get the admin password using a brute force attack.

All things considered, the production site is vulnerable only if the hackers were to get the FTP/SFTP or hosting passwords.

Hosting costs

A hosting service suitable for WordPress has to have some serious horsepower to handle all queries sent to the database. In terms of costs, we're talking about 12 Euros per month or thereabouts.

When talking about static WordPress, there are two things to consider in regards to hosting:

  • While we still need a server with PHP and a database, its only purpose will be to host the source WP instance. Admins will be the only ones to use it so the server won't have to deal with heavy traffic.

  • We need a server from which we'll serve the static HTML files to users. For that, we can use GitHub Pages, Netlify, or similar services.

Thanks to the simplification of the technology stack the costs come down right away. In my case, with the two-server setup, I managed to save 5 Euros and end up with a monthly cost of just 7 Euro.

Peace of mind

All this simplification has one more benefit - there are fewer things that can break down, fewer things can go south, which is always a good thing.

In addition to that, you can use Cloudflare or a similar service that will ensure that your site is equally snappy for users all around the world.

As a bonus, you'll get yet another layer of security, which will protect you against DDoS attacks and more.

Static WordPress - the drawbacks

As life teaches us, perfect solutions don't exist. This is true for using static WordPress as well.

First of all, you must remember that not all WordPress sites are created equal, and not all sites should be turned static. It's all about the content you want to present to the users.

If your site is a "read-only" affair, like a blog or a company website, nothing really stands in the way of going static.

However, if the content is dynamic and created by the users, converting to a static site might turn out impossible.

Workarounds

You have to remember that the conversion takes away some of WP features, too. Comments, forms, search - these won't work when your site is static.

Fortunately, you can add these features back using tools such as Reply Box, Kwes, and Algolia.

Build process

You might've gotten used to clicking "Publish" or "Update" and seeing your site updated with the new content. If you want a static WordPress, you'll have to deal with an additional step added to your workflow.

Fortunately, it's not a big one, but still, it's yet another thing you have to remember. Also, keep in mind that building the site can take a minute or considerably more - it all depends on the size of your site.

How to convert?

There are three ways to make your WordPress static:

Let's give each of these methods a closer look.

Plugin

Image loading...Using a plugin for static WordPress

My recommendation - use a plugin with the WP-CLI, which will help avoid timeout issues, and a CI/CD tool, which will allow to expand the process and make most of the tasks automatic.

The benefits of adopting this approach are:

  • The price - it's free, or you'll end up paying a small amount of money
  • You've got control over the entire process
  • More and more plugins expose API endpoints which make them compatible with this method

Static site generator

Image loading...Using static site generator for static WordPress

In this approach, the challenge lies in choosing the right generator for you. You can choose from numerous offerings, each of them a bit different, often using different programming languages under the hood.

The common ways of enabling communication between a generator and WordPress are either through using the WP REST API, or GraphQL plugins such as WPGraphQL or GraphQL API for WordPress.

The benefits of adopting this approach are:

  • You can use programming languages other than PHP
  • Price - free or very cheap
  • More and more plugins expose API endpoints which make them compatible with this method

Services

Image loading...Using services for static WordPress

If you don't have the time to get down and dirty with any of the described methods, you can leave the process to services that enable converting WordPress to static sites.

Basing on my experience with Strattic, I can tell you that it's a very quick and simple solution. In my case, going static took about 20 minutes, 15 of which were dedicated to transferring files.

The benefits of adopting this approach are:

  • It just works - no need to know or understand what's going on behind the scenes
  • Some of the services come with cool integrations out of the box

Should you turn your WP into a static site?

As you can see from the pros and cons I listed, there are some major gains to be had when converting to a static site.

Sure, there are some hurdles you'll have to overcome in certain areas, but there are many ways and tools to work around them.

To sum up, I encourage you to convert your WordPress to a static site if you present "read-only" content with no sign-ups, logins, and new content published every few minutes.

If that sounds like your website, then the effort put into going static will quickly pay back. Your users will love how fast your website loads, and you and your wallet will certainly appreciate all the savings you get thanks to lower hosting costs.

Read similar articles