I’ve been building most of my projects with React. I like my routing setup and know exactly how I want my apps to build and behave. However, one challenge kept bugging me: how to get faster page loads and better SEO for my React SPA — especially for blog pages — without having to switch to Next.js or rewrite my entire codebase.
Many coworkers asked me why I don't use Next.js or other frameworks like Gatsby, but I wasn’t ready to change my entire architecture or routing logic (I will discuss real reasons in a future post).
I wanted a solution that lets me keep writing React my way, but still get the SEO and performance benefits of static HTML files.
Why Static HTML Files Matter for SEO and Speed
Single Page Applications (SPAs) built with React usually serve a single index.html file and the client-side JavaScript handles routing. While this is great for user experience, it can hurt SEO because search engines might struggle to index dynamic content properly or it might slow down initial page load times.
Static HTML files — e.g. /blog/post/index.html
— allow search engines to easily crawl and rank every page individually, and let users get meaningful content faster without waiting for JavaScript to hydrate the page.
To solve this, I built a CLI tool called react-static-prerender.
What it does
- Prerenders your existing React app routes into real static HTML files — one per route, acting as multiple entry points into your SPA.
- After the initial page load, JavaScript takes over, and your SPA behaves exactly as before.
- It supports any bundler (Vite, Create React App, Webpack, or your own custom build scripts).
- It supports static and dynamic routes, so you can generate pages from CMS data, markdown files, APIs, JSON...
- Outputs files either as a nested directory structure (e.g.
/blog/post/index.html
) or flat files (blog-post.html
) depending on your preference.
What it doesn’t do
- It doesn’t require adopting new frameworks like Next.js or Gatsby. -You don’t have to change your existing routing setup or app structure. -No need to rewrite your codebase — you keep your React code exactly as it is.
Why I Built It
I wanted to keep my workflow simple, keep my codebase clean and still get the SEO and speed benefits static HTML can bring. This tool bridges the gap between fully static frameworks and SPAs — letting you have the best of both worlds.
How to Use It
I’ve spent a lot of time writing a detailed, clean README with examples and guides for:
-Setting up static or dynamic routes (including fetching routes from APIs or files)
-Using it with different bundlers like Vite, CRA, Webpack, Yarn, PNPM or custom build scripts
-Configuring flat vs nested output structure
-CLI flags for building and debugging
-Troubleshooting common issues
Check it out here:
github.com/jankojjs/react-static-prerender
Who Is This For?
-Developers who want better SEO and faster load times for React SPAs
-Teams who want to keep their existing React codebase and routing
-Anyone building blogs, e-commerce sites, documentation, or content-heavy React apps
-Projects that want to use CDN or static hosting without losing SPA behavior
Final Thoughts
If you want to keep writing React the way you like, but also want static .html files for SEO and performance, this tool might be what you’re looking for. I’d love to hear your feedback, feature requests or any edge cases you encounter.
Thanks for reading!
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.