Menu

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

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

DEV Community: javascript·Markus Delos Santos·1 day ago
#qBWN6qZm
#devtojavascript#devto#dev#prerender#status
Long article (1597 words) — no AI summary yet.
Reading 0:00
15s threshold

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 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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.