January 23rd, 2019
There’s a lot of talk about static site generators and static vs dynamic sites at the moment. But what does it all mean? And why is it so popular?
I learned about these topics a couple of weeks ago when I discovered HUGO and made this website.
The way I understand it, there are two main differences between static and dynamic generated sites:
Static sites (as the name implies) are websites that consist of a set of prebuilt files that are sent to the user from a file server upon request.
Dynamic sites, on the other hand, are built upon request from the user. When we visit a webpage with a complex CMS like WordPress, we first connect to the server. Then the server has to connect to a database, pull out some information, put that information into a template and generate the code, run some plugins and then display it to the visitor. This takes time and demands a lot of computational power. And if there is a lot of traffic, the server can slow down considerably.
Static pages are built at lanch and when updated, and never again. It mixes code and content, generates the appropriate files and uploads the files to a file server. All the server needs to do, is to send the files to the visitor. It doesn’t need to search a database, replace text, build code, loop through content etc. This makes them faster, more secure and cheaper. But what are the cons?
It’s possible to mix functions from both a static and a dynamic site, but if we look at a purely static site, they are a lot less flexible. There are things you just can’t do without a database or third-party solutions, like comments and search. And you can’t have any form of log in like WordPress or Joomla. But as mentioned, there are solutions for this, like the headless CMSes. You can also not have any kind of automated content without constantly rebuilding the site.
Pros static site
Less complex, and as such, much more secure. There is no database to hack, making the site less vulnerable
No need for updates
Much cheaper. All you need is a file server
You can serve much more users at once.
Consistent. It´s built one time, and it stays like that until you update it.
A webpage that sits on your local machine.
Can be connected to several CMS’s, and also edited in Git, code programs, text editors and more.
Cons static site
You may sacrifice a bit of flexibility
There are some things you just can’t do. Other functions may be a lot more complicated
Can’t have automated content
Functions like comments and even search are dependable on third-party solutions.
You can’t have any form of login without a database.
Cons dynamic sites
Much more vulnerable to hacking
You have to not only update the platform but also themes and plugins.
Slows down fast with a big user base.
Updates can potentially break functionality and/or change the appearance.
Why are sites like Wordpress so vulnerable to hacking? It’s not that the code is bad or that security isn’t prioritized, but there are so many of them. Almost 30% of all sites on the internet use Wordpress, and if we count the plugins and themes, the potential to be hacked is high. If someone can guess your database login, you are hacked.
With a static site, all you have is a file server. It may also be hacked, but there is a lot less chance, and your site also lives on your local machine, so it is a lot safer.
I was hacked last year, and my provider told me it was through a WordPress plugin. They offered me better security, but that also meant more money.