Headless-Render-API.com has several heuristics for automatically detecting when a page is done rendering:
But sometimes this isn't enough, for example, here are some edge cases we've seen:
Try our HTTP header: Prerender-Wait-Extra-Long: true
which will add approximately ~2s to your render time.
note: Headless-Render-API.com was previously known as Prerender.cloud (rebranded 2022-05-01)
This option is not recommended because it requires diligence and if not configured correctly causes your pages to time out.
When your page starts loading, set:
window.prerendercloudReady = false
and when it's ready to be pre-rendered, set:
window.prerendercloudReady = true
Note: You must set it to true
because that's what Headless-Render-API.com waits for before returning a response. If never set true
, it will just timeout.
In General, the approach looks like:
window.prerendercloudReady = false;
window.fetch("example.com/api/my-api").then(res => {
// do some rendering
window.prerendercloudReady = true;
})
In ReactJS this could look like:
but this gets hard to manage if you a big tree of components each making their own async requests.
componentWillMount() {
window.prerendercloudReady = false;
}
componentDidMount() {
window.prerendercloudReady = true;
}
// react doesn't call this on first render (hence componentDidMount)
componentDidUpdate() {
window.prerendercloudReady = true;
}
For extreme situations, you can simply set a timer:
window.prerendercloudReady = false;
setTimeout(() => {
window.prerendercloudReady = true;
}, 6000);