Prerender service down or timing out? Make prerender-node fall back to your own page
If your prerender service times out or goes down, prerender-node won't switch to your normal page on its own. If the service sends back an error status, such as a 504, the crawler gets that same status. The fix is a few lines in the afterRender hook. Return { cancelRender: true } when the render failed, and the request skips to your next middleware, which serves your own page.
What prerender-node does with a failed render
Here's the normal path. The middleware checks the user agent string against a default list of crawler user agents. Then it asks your prerender service for the page's prerendered HTML and returns that HTML from your server. Unless you set PRERENDER_SERVICE_URL, it uses the service already deployed by Prerender.io.
A render can fail in two ways, and the middleware handles them differently. In the first, the service answers with an error status. prerender-node writes the service's status code and headers straight to the response the crawler gets. In the second, the request to the service fails. The request's error handler catches that, and the error reaches your afterRender hook as err.
The first case is the one that's easy to miss. Prerender.io's status-code docs describe a 504 as "Gateway timeout. Rendering failed or timed out." So when a render times out on the service's side, a crawler can get a 504 from your server.
What an error status costs you in search
Google's crawler docs say server errors make Google slow down: "Google decreases the crawl rate for the site." Pages that are already indexed stay for a while, but they're eventually dropped. Google also removes from its index URLs that persistently return a server error.
Prerender.io's docs add AI answers to the picture. Crawlers often retry after a 504, but persistent failures still delay or block proper indexing. And a page that returns 504 repeatedly will eventually drop from indexes and AI-generated answers.
In short, one failed render is a blip. A page that fails every time a crawler asks for it is the real problem, and that's what a fallback is for.
Fall back to your own page with afterRender
The README says afterRender runs after the prerender service returns HTML. You can use it to cancel the prerendered response and skip to the next middleware. The README's own example use is a fallback for when Prerender returns errors, or when the HTML is missing expected content. Its sample returns { cancelRender: true } when err is set. Here's that pattern:
app.use(require('prerender-node').set('afterRender', function(err, req, prerender_res) {
if (err) {
return { cancelRender: true };
}
}));That only checks err. When the service answers with an error status, that status is what prerender-node writes to the crawler. So check the status code too:
app.use(require('prerender-node').set('afterRender', function(err, req, prerender_res) {
if (err || prerender_res.statusCode >= 500) {
return { cancelRender: true };
}
}));Keep err first in that condition. That way a failed request returns before your code reads the response.
If you cache renders, put the same check on the caching side. The README's Redis example has a comment for exactly this: "Don't cache responses that might be temporary like 500 or 504." A cached error page can keep getting served after the service recovers.
When the page comes back, but half empty
Not every failure arrives with an error status. Prerender.io has a 20-second default render timeout. If your page hasn't finished rendering by then, the service captures whatever state the page has reached. Its status-code docs say you can raise the timeout to as much as 60 seconds.
If that partial page comes back as a normal success, the status check above won't catch it. The README's "missing expected content" case is the answer. Pick a piece of markup every real page has, like its main heading, and return { cancelRender: true } when the rendered HTML doesn't contain it.
Pick the marker carefully. If some of your pages have no heading, use something else they all share, or the check will send working renders back to the fallback.
Find out why renders fail
A fallback keeps crawlers from getting errors, but you still want fewer failures. Check these first:
- Your firewall or CDN. Prerender.io says that 504 and 403 errors almost always mean your firewall is blocking or rate-limiting its requests. It names rate-limiting and DDoS-protection rules as the most common cause of 504s, even when no hard block is configured.
- What crawlers got in the meantime. The same Prerender.io page warns that crawlers may receive a partial page, an unrendered JavaScript shell, or an error response.
- Slow pages. If a page often misses the render timeout, make it faster or raise the timeout.
- The fallback itself. In a dev environment, point PRERENDER_SERVICE_URL at an address where nothing is listening, then request a page with a crawler user agent. If the fallback works, you get your own page back, not an error.
If you'd rather the service fall back for you
We built this behaviour into RenderSwap, our hosted prerender service. When a render fails, the crawler gets your origin's own page. That covers a timeout, a site that blocks the renderer, and a month past your cap. The dashboard lists the pages that fell back and the reason for each one.
It works with prerender-node as it is: you change the service URL and the token, and your middleware stays. In our checks on 4 November 2026 with the unmodified prerender-node 3.8.3, a page that never finished fell back to the origin's own page. The Free plan covers 1 verified domain and 500 fresh renders or 1 browser hour a month, whichever comes first. Keep the afterRender check either way, because a hosted fallback can't help if the request to the service itself fails.
Sources
- prerender-node middleware README and hooks
- prerender-node middleware source code (index.js)
- Prerender.io status codes reference
- Prerender.io guide to 504 and 403 render errors
- Prerender.io guide to empty or partial renders
- Google Search Central on HTTP status codes and crawling
Questions
Does prerender-node serve my normal page if the prerender service is down?
Not unless you set it up to. A failed request reaches your afterRender hook as err. Return { cancelRender: true } from the hook, and the request skips to your next middleware.
Will a 504 from my prerender service hurt my rankings?
One failure isn't the issue; repeated ones are. Google lowers the crawl rate when it sees server errors, and it removes from its index URLs that persistently return a server error. Prerender.io says a page that returns 504 repeatedly will eventually drop from indexes and AI-generated answers.
Should I cache a prerendered error page?
No. The prerender-node README's Redis example says not to cache responses that might be temporary, like 500 or 504. Cache only the status codes you'd be happy to serve again.
How long does Prerender.io wait before a render fails?
Its docs give a 20-second default render timeout, which you can raise to as much as 60 seconds. If a page hasn't finished by then, the service captures whatever state the page has reached.