Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby static site gen. & publishing new content

Tags:

gatsby

With the Gatsby static site generator project, since the site is rendering content files to html during the webpack build, does this mean that for something like a blog, every new post would require a fresh push to server?

If that's the case, does anyone have best-practices for that workflow?

like image 328
Brandon Avatar asked Jun 14 '16 17:06

Brandon


People also ask

Is Gatsby a static site generator?

Gatsby, on the other hand, is a static progressive web app (PWA) generator that offers code and data splitting out of the box. To boost performance, Gatsby loads only critical HTML, CSS, JavaScript, and other data.

What is Gatsby site generator?

Static Progressive Web Apps Gatsby. js is a static PWA (Progressive Web App) generator. You get code and data splitting out-of-the-box. Gatsby loads only the critical HTML, CSS, data, and JavaScript so your site loads as fast as possible.

Why is Gatsby a static website?

Rather than relying on servers to generate pages dynamically, pre-render all of them on build and use CDNs for a blazing fast and smooth experience for users all around the globe. Gatsby does static rendering. Which makes content available as HTML, and search engine optimized, no long initial load time.

What is static site generation?

A static site generator is a tool that generates a full static HTML website based on raw data and a set of templates. Essentially, a static site generator automates the task of coding individual HTML pages and gets those pages ready to serve to users ahead of time.


1 Answers

Yes, static sites must be rebuilt when you change one of your source files. In a database-backed website (e.g. Wordpress) HTML is built on-the-fly on every page request so if you change content in the database, this is immediately reflected in the site's HTML on the next page load.

Static websites don't build HTML on each page request. This is the reason they're so fast (and secure) as they do so little work. The server is just reading a file off disk. But this does mean that when you change or add to the site's content (e.g. new blog post) you do need to rebuild the site.

There's a number of good workflows for handling this "rebuild & push to server" process.

For my blog (bricolage.io) I just build the site locally and then commit the build files into Git and then pull these changes on my server. There I have a webserver (caddyserver.com) setup to serve the public folder. This somewhat manual process works as I rarely update my site.

For Github Pages, I'll add a simple deploy npm script something like "deploy": "gatsby build --prefix-links && gh-pages -d public". See what I did for react-headroom https://github.com/KyleAMathews/react-headroom/blob/master/website/package.json

There are a number of static website hosting companies that have built-in workflows for Gatsby. I highly recommend them if they fit your needs!

See these blog posts:

  • https://www.netlify.com/blog/2016/02/24/a-step-by-step-guide-gatsby-on-netlify
  • https://www.aerobatic.com/blog/gatsbyjs

Also in the coming months, Gatsby will be adding support for deploy plugins which will further simplify setting up a good workflow.

like image 189
Kyle Mathews Avatar answered Oct 16 '22 04:10

Kyle Mathews