June 19, 2017
For many years, publishing a website was out of reach many users. HTML authoring, hosting accounts, and managing the update of the hosted files was too much for average non-technical folks. Nowadays a user can sign up for a Tumblr account How To Easily Create a Blog with Tumblr How To Easily Create a Blog with Tumblr Read More and be typing their first post within minutes.
As users became more sophisticated, blogging platforms like WordPress provided ownership of their content. But WordPress and its peers still have a number of moving parts. This is overkill for someone who just wants to blog while still owning it. A recent answer to this is the static site generator (SSG). Let’s explore why you might want to consider one for your next online project.
The first pages on the Web were just that: individual pages that someone wrote as an HTML file and uploaded to a server. While a modern CMS (Content Management System) presents content as a page, in reality it is mashing up markup, database content, and real-time calculations. They are web applications that help users create content, store it, then serve it up to site visitors.
In contrast, static site generators are publishing tools. They’re not so different from tools like Adobe Acrobat, which takes an editable format (e.g. Microsoft Word) and converts it to a format 7 Free Online PDF Tools That Could Save You A Lot Of Work 7 Free Online PDF Tools That Could Save You A Lot Of Work The Web is full of awesome little tools that can help you alter PDF files without breaking a sweat. Let’s look at lesser known PDF tasks that may come in handy for you. Read More that’s easy to consume (.PDF). In this case, SSGs are doing the following basic tasks:
In the next section we’ll examine some of the advantages the “static” nature of SSGs provides over today’s CMSs.
For those used to working in a CMS like WordPress, some of the following will seem like a big change. But they make producing and maintaining some types of sites a lot easier. Let’s take a look at some of these advantages.
The below sections include commands and output from the Jekyll static site generator as an example. If you select a different SSG, the commands will be different, but the concepts are similar.
A major difference compared to a “traditional” CMS is that you’re installing static site generators on your local machine. For example, getting Jekyll up and running on an Ubuntu machine was as easy as the following command:
sudo apt-get install jekyllThen just start up a new project:
jekyll new mytestsiteYou’ll have the makings of a new site in the “mytestsite” directory with a number of default files. Take note of the “_posts” directory, which contains a Markdown file.
Static site generators are designed to work with offline, local content. There’s no need for a live internet connection to create a new post. You can draft the content, then run a “build” command later to create the post/page that will make its way to the Web. If you’re used to offline blog editors such as BlogDesk 4 Alternatives To Windows Live Writer For Blogging 4 Alternatives To Windows Live Writer For Blogging Microsoft recently announced the end of the Windows Live brand. In response to concerns, all Microsoft is saying about Windows Live Writer is it will “work great on Windows 8” – not whether development is… Read More it’s similar, except instead of pushing posts one at a time, you’re building the whole site locally.
Next, create your content in the “_posts” folder mentioned above. You can build your site when you’re ready by executing the following command from the project’s directory:
jekyll serveThis builds the entire site in a sub-folder, as shown below:
When complete, you can also view this site using Jekyll’s built-in web server at .
If you like what you see, you can simply upload all the files in the “_sites” folder to a web host What Is a Web Server? [MakeUseOf Explains] What Is a Web Server? [MakeUseOf Explains] If there is one thing that causes the most confusion for people that are new to the web design game, it’s the concept of a web server. When most people think of a “server”, they… Read More . Your site is ready to go!
Also, you’re able to create those posts in a format friendlier than raw HTML. Markdown is the most well-supported, but many SSGs can also accept others either out-of-the-box or via a plugin. Jekyll’s plugins include options like Asciidoc, orgMode, or reStructuredText. If you’re using one of these other markup languages, a quick config change or plugin install should be all you need.
Image Credit: GitHubInterestingly, most SSGs also accept HTML as an input. “Wait,” you’re saying. “I thought converting to HTML was the point of this whole thing!” But consider this: other formats not directly supported by SSGs can often export to HTML. Imagine a workflow where you (or other writers) author in LibreOffice using ODT, which gets converted (such as via Pandoc How to Easily Convert Between Document Formats in Linux How to Easily Convert Between Document Formats in Linux Switching to Linux can result in problems with file compatibility. For instance, documents don’t look the same in LibreOffice as they do in Word. This is just one reason why you need pandoc. Read More ) to raw HTML, which is further processed and styled by the SSG. It would take some elbow grease, but it’s entirely possible!
As mentioned above, most SSGs also support extensions or plugins to provide extra functionality. This range from automatically adding data to the site (e.g. date-based URLs for or related posts) to more “CMS-like” features like user authentication or comments. One plugin for the DocPad SSG even provides an administration panel!
Image Credit: npm### 5. Static Sites Are Fast
Between fetching content from the database and running any included code, loading some CMS pages can be sluggish. In contrast, static sites are already in the format the browser will consume. The only delay is in how long it takes the web server to send the page, and how long it takes the browser to render it How Do Browsers Display Web Pages, and Why Don’t They Ever Look the Same? How Do Browsers Display Web Pages, and Why Don’t They Ever Look the Same? Read More . But these are both things a CMS-driven site would also have to do.
The multiple moving parts of CMSs like WordPress, Drupal, and others open up attack vectors for the villains of the Interwebs. Access to a PHP file can allow an attacker to execute their own code on your site. A compromised database has led to headaches for e-commerce vendors The Sorry State Of Personal Data Security In E-Commerce The Sorry State Of Personal Data Security In E-Commerce Many of these retailers owe their entire being to the Internet, yet are incapable of following even the most basic of good data practices. Read More (as they’re in really a more sophisticated CMS).
@briancroxall perhaps missing: security much easier with static site generators.
— Martin Paul Eve (@martin_eve) March 25, 2017
On the other hand, all the programming magic of SSGs happens on your local machine. Thus, your biggest concern will be file permissions. Accidentally making a file writable to the world One Of The Most Important Tools In Linux - Understanding Chmod One Of The Most Important Tools In Linux - Understanding Chmod There are plenty of features that make Linux special, but one of them that makes it so secure is its permissions system. You can have fine-grain control over all the files in your system and… Read More would be a “bad thing,” but this is something that could happen to a CMS as well. However, since a static site doesn’t have any executable code within it and doesn’t access database content, it reduces the number of potential holes in your site’s security.
If you’ve ever managed a site, you know the moment of dread that comes along with seeing that “Upgrade available!” message in your admin panel. Sure, you’ll test it in your staging environment, but you never really know if that one code fix or oddly-formatted user comment will make it all blow up.
Compare this to static sites. Although new versions of the SSG tool may be available, these don’t impact anything on your live site. It will continue to chug along, oblivious to any upgrades that may or may not have happened. In the meantime you can upgrade your SSG, publish a new version of the site to test it out, and finally migrate the new version live. The same can be accomplished with CMSes, but not without considering things like database rollbacks and whether new user-generated content will be lost.
Not all sites are a good fit for static site generators. If you’re putting together a small personal site, or something like a traditional blog (i.e. a daily journal), the simplicity of SSGs might be for you. Basically, if you’re looking for one-way publishing of your text-and-graphics content to the web, a static site is a good choice.
But most modern websites aren’t glorified online journals. If you will need any of the following for your site, now or in the future, you should consider the caveats that come with static site generators.
Overall, static site generators are publishing tools ideal for users looking for a straightforward way to create some content and get it ready for the web.
What do you think? Would you be willing to give a static site generator a spin? Think a CMS is still the way to go? Let’s discuss below in the comments!
Image Credit: mihalec via Shutterstock.com