Prerender
Node server that uses Headless Chrome to render a javascript-rendered page as HTML. To be used in conjunction with prerender middleware.
Install / Use
/learn @prerender/PrerenderREADME
Prerender
Prerender is a node server that uses Headless Chrome to render HTML, screenshots, PDFs, and HAR files out of any web page. The Prerender server listens for an http request, takes the URL and loads it in Headless Chrome, waits for the page to finish loading by waiting for the network to be idle, and then returns your content.
The quickest way to run your own prerender server:
$ npm install prerender
server.js
const prerender = require('prerender');
const server = prerender();
server.start();
test it:
curl http://localhost:3000/render?url=https://www.example.com/
Use Cases
The Prerender server can be used in conjunction with our Prerender.io middleware in order to serve the prerendered HTML of your javascript website to search engines (Google, Bing, etc) and social networks (Facebook, Twitter, etc) for SEO. We run the Prerender server at scale for SEO needs at https://prerender.io/.
The Prerender server can be used on its own to crawl any web page and pull down the content for your own parsing needs. We host the Prerender server for your own crawling needs at https://prerender.com/.
Prerender differs from Google Puppeteer in that Prerender is a web server that takes in URLs and loads them in parallel in a new tab in Headless Chrome. Puppeteer is an API for interacting with Chrome, but you still have to write that interaction yourself. With Prerender, you don't have to write any code to launch Chrome, load pages, wait for the page to load, or pull the content off of the page. The Prerender server handles all of that for you so you can focus on more important things!
Below you will find documentation for our Prerender.io service (website SEO) and our Prerender.com service (web crawling).
Click here to jump to Prerender.io documentation
Click here to jump to Prerender.com documentation
<a id='prerenderio'></a>
Prerender.io
For serving your prerendered HTML to crawlers for SEO
Prerender solves SEO by serving prerendered HTML to Google and other search engines. It's easy:
- Just install the appropriate middleware for your app (or check out the source code and build your own)
- Make sure search engines have a way of discovering your pages (e.g. sitemap.xml and links from other parts of your site or from around the web)
- That's it! Perfect SEO on javascript pages.
<a id='middleware'></a>
Middleware
This is a list of middleware available to use with the prerender service:
Official middleware
Javascript
- prerender-node (Express)
Ruby
- prerender_rails (Rails)
Apache
Nginx
Community middleware
PHP
- zfr-prerender (Zend Framework 2)
- YuccaPrerenderBundle (Symfony 2)
- Laravel Prerender (Laravel)
Java
Go
Grails
Nginx
Apache
Request more middleware for a different framework in this issue.
How it works
This is a simple service that only takes a url and returns the rendered HTML (with all script tags removed).
Note: you should proxy the request through your server (using middleware) so that any relative links to CSS/images/etc still work.
GET https://service.prerender.io/https://www.google.com
GET https://service.prerender.io/https://www.google.com/search?q=angular
Running locally
If you are trying to test Prerender with your website on localhost, you'll have to run the Prerender server locally so that Prerender can access your local dev website.
If you are running the prerender service locally. Make sure you set your middleware to point to your local Prerender server with:
export PRERENDER_SERVICE_URL=http://localhost:3000
$ git clone https://github.com/prerender/prerender.git
$ cd prerender
$ npm install
$ node server.js
Prerender will now be running on http://localhost:3000. If you wanted to start a web app that ran on say, http://localhost:8000, you can now visit the URL http://localhost:3000/http://localhost:8000 to see how your app would render in Prerender.
To test how your website will render through Prerender using the middleware, you'll want to visit the URL http://localhost:8000?escaped_fragment=
That should send a request to the Prerender server and display the prerendered page through your website. If you View Source of that page, you should see the HTML with all of the <script> tags removed.
Keep in mind you will see 504s for relative URLs when accessing http://localhost:3000/http://localhost:8000 because the actual domain on that request is your prerender server. This isn't really an issue because once you proxy that request through the middleware, then the domain will be your website and those requests won't be sent to the prerender server. For instance if you want to see your relative URLS working visit http://localhost:8000?_escaped_fragment_=
Customization
You can clone this repo and run server.js OR include prerender in your project with npm install prerender --save to create an express-like server with custom plugins.
Options
chromeLocation
var prerender = require('./lib');
var server = prerender({
chromeLocation: '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
});
server.start();
Uses a chrome install at a certain location. Prerender does not download Chrome so you will want to make sure Chrome is installed on your server already. The Prerender server checks a few known locations for Chrome but this lets you override that.
Default: null
logRequests
var prerender = require('./lib');
var server = prerender({
logRequests: true
});
server.start();
Causes the Prerender server to print out every request made represented by a + and every response received represented by a -. Lets you analyze page load times.
Default: false
captureConsoleLog
var prerender = require('./lib');
var server = prerender({
captureConsoleLog: true
});
server.start();
Prerender server will store all console logs into pageLoadInfo.logEntries for further analytics.
Default: false
pageDoneCheckInterval
var prerender = require('./lib');
var server = prerender({
pageDoneCheckInterval: 1000
});
server.start();
Number of milliseconds between the interval of checking whether the page is done loading or not. You can also set the environment variable of PAGE_DONE_CHECK_INTERVAL instead of passing in the pageDoneCheckInterval parameter.
Default: 500
pageLoadTimeout
var prerender = require('./lib');
var server = prerender({
pageLoadTimeout: 20 * 1000
});
server.start();
Maximum number of milliseconds to wait while downloading the page, waiting for all pending requests/ajax calls to complete before timing out and continuing on. Time out condition does not cause an error, it just returns the HTML on the page at that moment. You can also set the environment variable of PAGE_LOAD_TIMEOUT instead of passing in the pageLoadTimeout parameter.
Default: 20000
waitAfterLastRequest
var prerender = require('./lib');
var server = prerender({
waitAfterLastRequest: 500
});
server.start();
Number of milliseconds to wait after the number of requests/ajax calls in flight reaches zero. HTML is pulled off of the page at this point. You can also set the environment variable of WAIT_AFTER_LAST_REQUEST instead of passing in the waitAfterLastRequest parameter.
Default: 500
followRedirects
var prerender = require('./lib');
var server = prerender({
followRedirects: false
});
server.start();
Whether Chrome follows a redirect on the first request if a redirect is encountered. Normally, for SEO purposes, you do not want to follow redirects. Instead, you want the Prerender server to return the redirect to the crawlers so they can update their index. Don't set this to true unless you know what you are doing. You can also set the environment variable of FOLLOW_REDIRECTS instead of passing in the followRedirects parameter.
Default: false
Plugins
We use a plugin system in the same way that Connect and Express use middleware. Our plugins are a little different and we don't want to confuse the prerender plugins with the prerender middleware, so we opted to call them "plugins".
Plugins are in the lib/plugins directory, and add functionality to the prerender service.
Each plugin can implement any of the plugin methods:
init()
requestReceived(req, res, next)
tabCreated(req, res, next)
pageLoaded(req, res, next)
beforeSend(req, res, next)
Available plugins
You can use any of these plugins by modifying the server.js file
basicAuth
If you want to only allow access to your Prerender server from authorized parties, enable the basic auth plugin.
You will need to add the BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD environment variables.
export BASIC_AUTH_USERNAME=prerender
export BASIC_AUTH_PASSWORD=test
Then make sure to pass the basic authentication headers (password base64 encoded).
curl -u prerender:wrong http:/
Related Skills
node-connect
337.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.2kCommit, push, and open a PR
