Bright Labs

How to return a 404 status code in a single-page app (and avoid soft 404s)

In a client-side single-page app, using meaningful HTTP status codes can be impossible or impractical, so Googlebot queues pages with a 200 HTTP status code for rendering instead of seeing a 404. Here's the fix: use meaningful HTTP status codes like 404 where you can, tell Google not to index the page with a robots meta tag or header, or output <meta name="prerender-status-code" content="404"> when serving crawlers through Prerender.io.

The catch is how client-side routing works. Some JavaScript sites use the app shell model, where the initial HTML does not contain the actual content. Google has to execute JavaScript before it can see the actual page content that JavaScript generates, and using meaningful HTTP status codes can be impossible or impractical.

Google processes JavaScript web apps in three main phases: crawling, rendering, and indexing. If robots.txt marks a URL as disallowed, Googlebot skips making an HTTP request to it and skips the URL.

For allowed URLs, Googlebot uses HTTP status codes to find out if something went wrong when crawling the page. It queues all pages with a 200 HTTP status code for rendering, unless a robots meta tag or header tells Google not to index the page. Once Google's resources allow, headless Chromium renders the page, executes the JavaScript, and Google uses the rendered HTML to index the page.

Keep queue timing in mind when you debug. A page may stay on Google's rendering queue for a few seconds, but it can take longer than that. To tell Googlebot if a page can't be crawled or indexed, use a meaningful status code, like a 404 for a page that could not be found or a 401 code for pages behind a login. You can also use HTTP status codes to tell Googlebot if a page has moved to a new URL so the index can be updated accordingly.

Fix soft 404s inside your app without a prerender server

Before you touch status tags, check how your router builds links between views. For single-page apps with client-side routing, Google's JavaScript SEO guide says to use the History API to implement routing between different views of your web app. Don't use fragments to load different page content.

This one is easy to miss if you still use hash routes. Googlebot can't reliably resolve fragment URLs, and avoiding fragments ensures Googlebot can parse and extract your URLs.

To avoid soft 404 errors when using client-side rendering and routing, Google documents specific strategies. Check these rules in your app:

Override status codes when serving crawlers through a prerender layer

Not all bots can run JavaScript, and server-side or pre-rendering makes your website faster for users and crawlers. By default, Prerender.io caches pages and returns a 200 OK status code. If a page has been deleted or permanently moved, AI crawlers and search engines will receive the wrong signal unless you override it.

When a page is deleted or permanently moved, use the prerender-status-code meta tag to override the default 200 OK response with a 404 status code:

Status override meta tag from Prerender.io crawler-ready pages guide
<meta name="prerender-status-code" content="404">

Here's the catch: only use these meta tags when you need to override the default 200 OK response, such as when a page is deleted or permanently moved. Applying them to live, indexable pages signals the wrong status to crawlers. Check your route cleanup code so an error meta tag doesn't linger after navigation.

Pages with dynamically loaded content—such as data fetched via AJAX—hit another catch. Prerender.io estimates when a page is ready by counting in-flight network requests. On AJAX-loaded pages, that estimate may be too early, and Prerender.io may cache an incomplete page.

You can control that timing with window.prerenderReady. Set window.prerenderReady to false at page load to tell Prerender.io to keep waiting. Then set window.prerenderReady = true inside the callback or promise that resolves your last data fetch—not on a timer, because timer-based approaches risk caching a page that is still mid-render.

Full-screen consent banners are easy to miss too. If Prerender.io caches a page with a full-screen consent banner, crawlers may receive a page with little or no readable content. If you suppress the consent banner for crawler user agents, your website visitors are unaffected and the banner continues to display normally for them.

Keep temporary errors out of your cache and verify the response

If you use the prerender-node middleware, it checks if a request is from a crawler by checking the user agent string against a default list of crawler user agents. It checks to make sure the request isn't for a resource like JS or CSS, then makes a GET request to the prerender service for the page's prerendered HTML.

You can limit which URLs get prerendered by supplying a whitelist or blacklist. If a whitelist is supplied, only URLs containing a whitelist path are prerendered. If a blacklist is supplied, all URLs are prerendered except ones containing a blacklist path.

Two options help with proxy and protocol setups. prerender-node provides a protocol option to hard-set the protocol, which is useful for sites available on both http and https. It also provides a host option to hard-set the host, which is useful for sites behind a load balancer or internal reverse proxy.

When setting up prerender-node, you can add a beforeRender function and an afterRender function for caching. Do not cache responses that might be temporary like 500 or 504. You can also use afterRender to cancel the prerendered response and skip to the next middleware, letting you implement your own fallback behavior when Prerender returns errors or the HTML is missing expected content.

Before you call it fixed, check what crawlers actually receive. The best way to test a prerendered page is to set the User Agent of your browser to Googlebot's user agent and visit your URL directly. Open the page source and check that you see the rendered output you expect.

Running RenderSwap as your prerender backend

If you run a single-page app and want a hosted prerender option, RenderSwap opens your public pages in a browser and serves the finished HTML to search and AI crawlers. You keep your existing prerender-node middleware and swap two values: the service URL and your RenderSwap token. In checks run on 4 November 2026 against Chrome 156 and unmodified prerender-node 3.8.3, all 8 of 8 swap checks passed, including returning 401 without a token, returning 403 on an unverified domain, serving cached hits without a browser, and falling back to your origin on timeouts or failures.

When a render fails or times out, RenderSwap returns your origin's own page and logs the failing URL in its dashboard under reasons like Timed out, Blocked as a bot, Render failed, or Empty page. Sign-up asks for no email or card, and you prove domain control with a DNS TXT record. RenderSwap Free costs $0 for 1 verified domain and gives 500 fresh renders or 1 browser hour a month, whichever comes first. RenderSwap Pro is $19/month for 3 verified domains and gives 30,000 fresh renders or 30 browser hours a month, whichever comes first, with $0 overage because past the cap your origin answers.

Sources

Questions

Why does my single-page app return 200 OK for URLs that do not exist?

In client-side rendered single-page apps, routing is often implemented as client-side routing, which can make using meaningful HTTP status codes impossible or impractical. Under the app shell model, initial HTML does not contain the actual content, and Googlebot queues all pages with a 200 HTTP status code for rendering unless a robots meta tag or header tells Google not to index the page.

When should I use the prerender-status-code meta tag?

Only use status override meta tags such as <meta name="prerender-status-code" content="404"> when you need to override Prerender.io's default 200 OK response, such as on a deleted or permanently moved page. Applying them to live, indexable pages signals the wrong status to crawlers.

What happens if my SPA loads data with AJAX before setting a 404 status meta tag?

In Prerender.io, readiness is estimated by counting in-flight network requests, which can trigger too early on AJAX-driven pages and cache an incomplete page. Set window.prerenderReady to false on page load to tell Prerender.io to keep waiting, then set window.prerenderReady = true inside the callback or promise that resolves your last data fetch rather than on a timer.

How do I avoid caching temporary 500 or 504 errors in prerender-node?

When setting up prerender-node, you can add beforeRender and afterRender functions for caching and avoid caching responses that might be temporary like 500 or 504. You can also use afterRender to cancel the prerendered response and skip to the next middleware so you can implement your own fallback behavior when Prerender returns errors or the HTML is missing expected content.

Related