weare-phantomjs-html
v0.4.4
Published
Render URLs and return their HTML content.
Downloads
1
Maintainers
Readme
weare-phantomjs-html
This module enables retrieval of the HTML output of URLs via an easy to use middleware.
Install
npm install --save weare-phantomjs-html
How to use
1. Use the ExpressJS middleware
This middleware need to be used before any routing is done. It will detect if the current request
is made from a crawler using the User-Agent
header and _escaped_fragment_
URL query param.
If a crawler is detected, it will return a PhantomJS rendering of the page that suitable for those crawlers.
var phantomjsHtml = require('weare-phantomjs-html');
// output PhantomJS render of pages if the request is made by a crawler
app.use(phantomjsHtml.middleware());
2. Delaying the PhantomJS output
In single pages apps, there is often JavaScript executed after the page has loaded to load or display data. You can instruct the rendering script to wait until your app is ready like so :
In the <head>
section of your HTML pages :
<script type="text/javascript">
window.phantomjsHtmlReady = false;
</script>
And when the page is ready to be rendered, just set phantomjsHtmlReady
to true
.
window.phantomjsHtmlReady = true;
Source
Original module: phantomjs-html