Use WordPress as a Static Website Generator

Updated on June 05, 2017

That’s one of the reasons why more and more people turn to static website generators. Jekyll is one of the most popular ones, which you can use to host your whole website or blog on GitHub Pages and push your new content with one command. The downside? For the laymen it’s not easy (to say the least) to set it up, and even for developers it can be time-consuming. If you have a free afternoon to learn more about Jekyll then take a look at this article by Barry Clark, it’s the most detailed tutorial on the topic that I know of.

However, if you’d rather just speed up your current WordPress site, you can do that too! You just have to remember that if you use WP in that way, you’ll have to make sacrifices: there won’t be any “real-time” dynamic content on your site, at all. No “recommended articles for you” widget that’s different for each visitor, you can’t use WordPress’s built-in commenting system and so on. Everything that is server-side (PHP) generated will become static and updated once a day for example.

Static website generators will create a complete HTML page based on your content and a given templating system (with probably a theme specified) and once it’s done, no matter how many people visit your site, it won’t be regenerated; not unless you type in a specific command on your computer! They’re solving the commenting “problem” by either not using it at all, or switching to JavaScript based solutions, the most popular being Disqus, but Facebook and Google Plus comments (and others) will work too. I can personally vouch for Disqus, it’s a great system that integrates with WordPress very well, plus I don’t even remember the last time we had to deal with a spam!

There are a couple of WordPress caching plugins that you can use to create static HTML files of your posts and pages, but if you’re using Nginx as your web server (and if you don’t, you really should, but that’s a topic for another article) you can just flip the full page caching switch on and set it to expire in a day or a week. The longer period you can “afford” to set it to, the better. What happens next is that the first visitor will have the server generate the complete, cached HTML files and any consecutive visitors within the predefined expiration period will get served those files.

static_5ms

For comparison, based on our recent tests while a WordPress page with a premium theme and WooCommerce activated will take about 250ms to get fully built and served, you can go as low as 110ms with HHVM, but the same page will be handed over in just 2 to 5ms when it comes from a prebuilt FastCGI cache! That’s a 50x performance improvement, not to mention that it won’t eat up hardware resources, so you’ll be able to handle enormous waves of traffic if it comes to that!

How to set it up, you ask? Well if you manage your own servers here’s an extremely detailed guide by DigitalOcean that you can follow. If you have a shared/managed hosting account, you can ask your support team to set it up for you. And if you’re a Kinsta WordPress Hosting client, you open up a ticket with our support team within your MyKinsta dashboard and request a longer cache duration.

Just please make sure first that you fully understand the consequences of doing so.

This article was written by Mark Gavalda

Mark has many years of experience leading teams in the fields of marketing, web design and development. As a dev guy he used his WP expertise to collect the know-hows of creating a reliable and customer friendly hosting company to satisfy the increasing demand of clients. He is an urban cyclist and autodidact who never stops learning new skills.

Hand-picked related articles

  1. Gravatar for this comment's author
    Tim Nash August 5, 2014 at 7:07 pm

    Not really sure I would consider turning on Nginx Full page caching creating a static site generator any more then using a proxy cache like Varnish or Cloudflare. However there a few good solutions, to generate flat html files from WordPress to create a real static site generator. I recently wrote a post about a couple of them https://timnash.co.uk/using-wordpress-static-site-generator/

    1. Gravatar for this comment's author
      Mark Gavalda August 7, 2014 at 7:19 am

      Hey Tim, thanks for stopping by! Yep you’re right it’s similar to having Varnish in front of your web server with an extreme long invalidation time. We don’t use Varnish, but it can be done with that too (and all similar software) of course.
      I’ll take a look at the article you linked, seems like it has a good couple of gems in it! :)

  2. Gravatar for this comment's author
    Tom Harrigan August 5, 2014 at 8:03 pm

    Does that same WooCommerce page that’s loading in 2-5ms actually work? Handling payment processing and checkouts don’t seem like things that would ever jive on a static site…

    1. Gravatar for this comment's author
      Mark Gavalda August 7, 2014 at 7:24 am

      Hi Tom, the rule of thumb is: what you wouldn’t be able to do with an HTML-only site, you won’t be able to full page cache (for too long). So here’s the deal with WooCommerce: you can cache the “static” front page, categories, product pages (if you don’t change them too often) and then yes, it will load in a couple of milliseconds! But as soon as someone clicks “add to cart” you’ll have to switch to a non-cached (or object cached as a maximum) version otherwise they’ll see the cart always empty! There are ways to do this with Nginx too: adding exception rules for POST http request method, placing a cookie on that particular user’s machine so they’ll be always served non-static content until the cookie exists. Or monitoring SESSIONs, etc. It’s a bit more technical than the simple solution I outlined in this article :)

  3. Gravatar for this comment's author
    Alex Thompson August 28, 2014 at 4:29 am

    I’ve been working on another approach to making a CMS static. I have a web crawler that can take a mirror snapshot of a wordpress site and then host the static output separately. The advantage is the CMS then doesn’t need to have good performance or reliability, it could even be shut down most of the time. http://www.primoca.com

  4. Gravatar for this comment's author
    Clyde Phillips September 30, 2014 at 6:59 am

    Hey Mark, I have a client who’s requested to have his wp/woocommerce site made static to be taken on a USB drive to his retail outlets that have limited or restrictions on internet for cateloguing and reference purposes. Would you recommend any solutions that would allow me to do this?

    I’ve tried wpstatic but while it pulls all the content, it leaves the CSS layouts. I’ve also tried Really Static, which pulls the full site and CSS layout, except ignores my woocommerce pages? So Im kinda stumped.

    1. Gravatar for this comment's author
      Mark Gavalda October 1, 2014 at 8:00 am

      Hey Clyde, I think you’ll need more for that than a simple static site generator! Because it will have to update the links and routes to assets and whatnot. There are a couple of software working towards “make my website offline” by ripping the whole thing and creating an executable out of it! You should search for those IMO! Good luck.

  5. Gravatar for this comment's author
    Victor-Alexandru Truică November 26, 2015 at 12:17 pm

    WP Super Cache or Varnish can do the job quite ok, that is if the user/multiple users need access to the admin panel online.

    In my case, I decided not to have anything WordPress related online. It rids me of the hassle of maintaining it (updates / backup / stuff just going wrong / getting compromised).

    My wordpress now resides isolated in a VM, which will then generate the static content to be uploaded on the host.

    1. Gravatar for this comment's author
      tiptronic February 8, 2016 at 8:21 am

      502 Bad Gateway ;)

    2. Gravatar for this comment's author
      Marcos Borges May 1, 2016 at 4:06 pm

      Would have loved to seen your solution Victor. I’m looking on doing the same thing with a website I own.

      1. Gravatar for this comment's author
        Victor-Alexandru Truică May 3, 2016 at 11:53 am

        There were some minor intreruptions, but it’s working now :)

    3. Gravatar for this comment's author
      J.T. Brown III August 26, 2016 at 7:39 pm

      Hi Victor, I’m very interested in your ‘isolated VM’ WP solution. Could you please reply with the link to your blogpost? Many thanx! -JT

  6. Gravatar for this comment's author
    Hitesh Parekh July 4, 2017 at 8:07 pm

    This is a great tool if you want to deploy a static website fast since there is no need for other complicated configurations.

Leave a Reply to Hitesh Parekh Cancel reply

Use WordPress?

Join 20,000+ others who get our FREE weekly newsletter with WordPress tips on how to drive more traffic and revenue to your business!

You have Successfully Subscribed!

Send this to a friend