Static site generator pros and cons
Today, there are distinct ways of developing a website: a programmer can create a site in a text editor, and even in a notebook, or they can use special software tools. As a rule, the base of the site is some kind of a content management system that simplifies routine actions.
In general, there are static and dynamic sites. Static websites are HTML pages that a server displays when the customer accesses them. These displayed pages are unchanged, and the only way to edit them is by altering the page code. A dynamic type has another approach to displaying pages. There is a kind of instruction according to which pages are formed every time the client accesses them. For example, the site menu, design, recent articles, etc. are automatically generated on the web and the site administrator doesn’t need to edit the code when adding new content.
From the above information, we can think that in comparison to static, dynamic systems are more beneficial. It was so until the static generator has been created.
Previously, static sites were created only by writing code in a text editor, which complicated the process and made it difficult to add new content to the site. Now a static generator has a solution to this problem: it creates static HTML pages using templates. They improve the overall performance, as serving HTML needs fewer resources, and customization of the client-side is now much easier. However, there exist both advantages and disadvantages of the generator.
Pros of the static site generators
A static site generator is a relatively new tendency in web development. It is a modern and competitive system with an appealing set of features. Most of the generators have the following benefits:
1. Excellent performance
Many CMS programs provide built-in caching systems that generate pages and reuse them when needed. This is effective, but there are a few unnecessary actions such as checking cache files and re-generating pages. Using the same template, a static site outperforms the one created on CMS. Generators can also compress files for making less loading.
2. Fast speed.
The time spent between downloading database content and running CMS page code can be huge. In contrast, ready-made pages of static sites can immediately be used in a browser. In addition, because the output of the static site generator is HTML, it can be hosted on any web server that generates files. And a programmer doesn’t need to install, configure, and update anything else.
3. Independence from data storage and its crashes.
First, static sites can perform without databases, representing only texts, graphics, and other files. Secondly, even the use of the database and its crash will not affect the performance of the site, because all the information for display will still be in text files. And the database is only a source from where the programmer takes data at the time of generation.
4. High level of security
CMS giants like WordPress, Joomla, or Drupal are constantly attacked by hackers, and their clients become sources of malware. For example, over 20 million sites are produced by only WordPress and it is easy for hackers to find a flaw in one system with unreliable functionality to make potential damage to others. Finding a hole in a static system is almost impossible. Even if we assume that some plugin will create leaky code, the probability of global infection is minimal because of the local nature of the static site.
5. Support of many formats
Site generators usually support multiple program languages. Also, the programmer doesn’t need to stop his choice on one of them as a quick setup allows him to change the markup language directly in the process of work.
6. Wide variety of plugins and templates
Most static generators support extensions and many plugins for providing additional functionality. Today the programmer can automatically add data to a site (such as date-based URLs) or use such dynamic functions as user authentication or comments.
New static site versions affect nothing on the actual site. It means the site will keep working, not depending on any updates that might or might not happen. The programmer can update the tools of the generator, test them, and finally transfer the new version of a site to use. The same actions can be done with a CMS, but here the database must be rolled back and there is a big risk of losing the previous content.
Cons of the static site generators
Besides the benefits, the static site generator as any web development product has its minuses:
- Working with a large resource
It is easy to work with the generator for a small blog that updates every couple of days. However, it is more difficult for a large information resource where several authors post news and records in real-time. In CMS, changes are implemented using a multi-user interface. In generators, each author makes changes manually, switching pages, and rebuilding the whole site. Thus, because of the time wasted for administration, the speed and security of static sites become meaningless.
A person without special programming knowledge can operate the site on CMS. Static generators do not provide such an opportunity, it is impossible to delegate administrative rights. Here, the only solution is implementing minor content changes, with the risk for the actual site.
- Limited functionality
The static functionality is still small. It is possible to add a registration form, attach comments, and individual elements. However, in comparison with the dynamic site, such a performance will seem to be of poor quality. In addition, searching by resource or a built-in forum is still an unaffordable function for existing generators.
- Data binding
Generators are vulnerable to attempts by novice developers to revive the site. The programmer can manually add dynamic elements to a static site such as scripts, widgets, animation. And the generator processes all this information and creates the site with both necessary and wasted information. As a result, the programmer risks getting layout problems, errors, and incorrect display. That means while the CMS deletes everything that does not fit into the selected template, the generator will thoughtlessly process the new code. Thus, a programmer will have to spend additional time adjusting and assembling the code.
- Static sites can be out of date
If the company dynamically fulfills the information on its site, then the static type can be not a suitable choice for it. Besides, the copyright notice on the web page’s corner shows its date and last renewing. If it says that the updated time was a long time ago, the reputation of the company statistically falls down. These outdated bits are perilous for a static type as they don’t provide new data, functions, and content that are today required by modern clients. Some smart programmers found the solution to out-of-date static sites by renewing them on January 1st and adding some extra features and designs.
Why is a static generator relevant today?
Every week new static site generators appear and often it becomes more difficult to keep up with them and their new features. Why is it so? What factors make them relevant today?
- Changes in browsers.
A modern browser not only displays information from the network but can also launch web applications, locally save data, and even open electronic documents, multimedia files, and more. They are designed to communicate with web servers and provide user access to the sites. Since browsers are constantly developing, today there is no need for the dynamic functions on the webserver. There are so many browser extensions that each customer can choose whatever he wants and needs on its client-side setup.
- The content delivery network becomes a mainstream.
The programmer can use the content delivery network on a dynamic site, but he will have cache reversal issues. In addition, the problem of caching on separate nodes requires complex work and spending much time on it. On the contrary, a static site can be hosted directly on the CDN. Generators can quickly transfer the cache from the nodes to the final users and set up the configuration. All these tasks are workable and fully automated.
- Performance is always in the first place.
Today, a properly configured static generator on a CDN has turned to be the best in performance. Developers would rather regenerate HTML than waste time and facilities changing a page for every HTTP request. Besides, a static generator solves many performance problems during development itself. Even if the dynamic site has a good level of caching, there is always a risk that individual requests will unnecessarily load the cache and gradually slow down the entire system. In the generated site, it does not matter how long it takes for the template engine to build the site, as this does not affect final users.
- Implementing build tools
Today, front-end developers have adapted build systems, package managers, compilers, and translators for their needs. It all started with Grunt, and now such things have become the basis for the most recent projects. With the dominance of build systems, static generators are often used by front-end specialists, while traditional PHP systems for dynamic sites look alien in today’s web development.