Prerender decides whether a page should be cached based on the status code returned. Most single-page applications will return a 200 status code for every page. This might be problematic as URLs that don't exist and URLs that redirect visitors will be cached, and over time, these pages accumulate in the cache, leading to extra charges.
To fix this, you can add meta tags to the head section of the pages to let Prerender know how the pages should be handled.
In the case of soft-404 pages, you can add the following meta tag:
<meta name="prerender-status-code" content="404">
In case of pages that redirect visitors to another page, add the following two meta tags:
<meta name="prerender-status-code" content="301">
<meta name="prerender-header" content="Location: http://www.example.com">
The page might be captured before the meta tag is injected into the head section of the page. Which might cause the returned status code to be inconsistent or stay 200. In this case, adding the following script tag to the top of the head section of the page should resolve the issue.
<script> window.prerenderReady = false; </script>
We will wait until window.prerenderReady is true before saving the HTML. This should be executed after the page is ready and the status code meta tags are already injected.
window.prerenderReady = true;
You can also add this flag to your other pages and change the variable true when the page is fully loaded to ensure they are captured correctly.