Skip to content

Gatsby

Gatsby is a React-based static site generator. It outputs a fully static site to public/ by default. pageflare integrates as a post-build step via npm scripts.

Gatsby has a plugin system with an onPostBuild hook, but the simplest approach is chaining pageflare in your build command.

Terminal window
npm install -D @pageflare/cli

Chain pageflare after gatsby build in your npm scripts:

package.json
{
"scripts": {
"build": "gatsby build && pageflare public/ --in-place"
}
}

Create a pageflare.jsonc in your project root:

pageflare.jsonc
{
"minify_html": true,
"minify_css": true,
"minify_js": true,
"js_defer": true,
"lazy_images": true,
"img_dimensions": true,
"font_swap": true,
"preconnect_hints": true
}

Gatsby handles image optimization via gatsby-plugin-image and minifies JS/CSS via webpack, but does not optimize the final HTML output. pageflare adds:

  • HTML minification
  • Lazy loading for images not using gatsby-plugin-image
  • JavaScript defer and loader injection
  • Font display swap and self-hosting
  • Preconnect hints for third-party origins
  • Critical CSS extraction (Pro)
  • Responsive image srcset generation (Pro)

pageflare replaces several Gatsby plugins. After adding pageflare to your build, you can remove:

Packagepageflare equivalent
gatsby-plugin-minify / gatsby-plugin-minify-htmlHTML minification
gatsby-plugin-preload-fontsFont preloading and self-hosting
gatsby-plugin-preconnectPreconnect hints
gatsby-plugin-sitemapSitemap generation via llm.sitemap config
gatsby-plugin-imageKeep — Gatsby’s image pipeline is tightly integrated; pageflare handles images that bypass it
.github/workflows/build.yml
- name: Build Gatsby
run: gatsby build
- name: Optimize with pageflare
uses: getappz/pageflare-cli@v1
with:
args: "public/ --in-place"
netlify.toml
[build]
command = "gatsby build && pageflare public/ --in-place --no-progress"
publish = "public"
vercel.json
{
"buildCommand": "gatsby build && pageflare public/ --in-place --no-progress"
}

Set the PAGEFLARE_LICENSE environment variable to unlock Pro optimizations:

Terminal window
PAGEFLARE_LICENSE=your-key npm run build

Gatsby static output works with any hosting provider:

JS defer breaks client-side navigation Gatsby uses client-side routing via @reach/router. If deferred scripts interfere with page transitions, disable JS deferral:

{ "js_defer": false }

Duplicate image optimization If you use gatsby-plugin-image, Gatsby already handles responsive images and lazy loading for those images. pageflare will skip images that already have loading="lazy" and srcset attributes. The two work safely together.

pageflare processes 0 files Verify Gatsby finished building — gatsby build can fail silently on GraphQL errors. Check that public/ contains HTML files before running pageflare.