React

Refresh Gatsby Content Without Restarting Development Server

Stop wasting time waiting for your Gatsby development server to restart and use the refresh feature!

Written by Gregory Gaines
1 min read
0 views
School of colorful fish and reef
Photo by Shaun Low on Unsplash

Table of Contents

I can't count how many hours I've wasted staring at my terminal waiting for the Gatsby development server to restart after editing content. Luckily, Gatsby can expose an endpoint to refresh content without restarting the whole server.

Prerequisite

Enabling Refresh Endpoint

Add ENABLE_GATSBY_REFRESH_ENDPOINT=true to your development environment variables to enable the refresh endpoint. The endpoint exposes as http://localhost:8000/__refresh.

Shell
.env.development
1ENABLE_GATSBY_REFRESH_ENDPOINT=true

Triggering Refresh Endpoint

Using postman, send an HTTP POST request to the http://localhost:8000/__refresh endpoint.

Much faster than a complete server restart.

Using the Terminal

The refresh endpoint can also be triggered using the terminal on Unix-based operating systems.

Shell
1curl -X POST http://localhost:8000/__refresh

Conclusion

The refresh feature is enabled by adding the ENABLE_GATSBY_REFRESH_ENDPOINT=true development environment variable. The endpoint is exposed as http://localhost:8000/__refresh and triggered by POST requests.

If you believe I've helped, consider signing up for my newsletter or supporting me.

About the author.

I'm Gregory Gaines, a software engineer that loves blogging, studying computer science, and reverse engineering.

I'm currently employed at Google; all opinions are my own.

Ko-fi donationsBuy Me a CoffeeBecome a Patron
Gregory Gaines

You may also like.

Comments.

Get updates straight to your mailbox!

Get the latest blog updates about programming and the industry ins and outs for free!

You have my spam free, guarantee. 🥳

Subscribe