Chapter 5. Adding Dynamic Elements

Now  that you’ve made the decision to use a static site generator (woo!), you may discover that you’ve forgotten one little detail that seems to require a dynamic application server of some sort. Perhaps you have a contact form. Maybe you want to add discussions to your blog. Does this mean you’ve made a horrible mistake and have to revert everything you worked on? Of course not!

Multiple different services exist that enable you to add dynamic features back to your site. In some cases, it is nearly impossible for the end user to tell that anything “special” is being done at all. To them, it simply appears as if your site is doing whatever it needs to on the backend, when in reality you’re still using simple static files.

In this chapter, we’ll discuss how to add dynamic elements back in to your static site. We’ll focus on:

  • Forms
  • Comments
  • Search

We’ll also discuss some other options for data types, like events and generic sets of data.

Handling Forms

Since the dawn of the web itself, forms have been an integral part of how users interact with your site. Moving to a static site doesn’t make forms themselves magically stop working. They still render. You can still interact with them using JavaScript. But if you want the form to do something on a server or to communicate with someone else, then you’ll be out of a luck when using a static site. Luckily, a number of options exist for adding basic form processing to your site. Let’s ...

Get Working with Static Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.