pppr is a zero-configuration prerender service. If you develop a web via client-side rendering (such as Vue, Angular, React...), you can integrate Nginx (or other reverse proxy) and pppr for search engine crawler (such as googlebot, bingbot...) and social network (such as Facebook, Twitter...) to render complete HTML.
const pppr = require('pppr');
app.use(pppr());
npm i pppr
app.use(pppr());
// equals to
app.use(pppr({
cache: true
}));
If you want to turn off cache, you can do below configuration.
app.use(pppr({
cache: false
}));
If you want to modify cache parameter, you can do below configuration.
app.use(pppr({
cache: {
max: 50, // LRU cache entry max count (default is 50)
ttl: 300000 // LRU cache entry ttl (milliseconds, default is 300000)
}
}));
If it renders occur timeout, you can retry render again.
app.use(pppr({
retryTimes: 5
}));
If endpoint conflicts, you can change it.
app.use(pppr({
endpoint: '/render'
}));
If you want to do something before/after render, you can do below configuration.
app.use(pppr({
beforeRender: (userAgent, url) => {
// do something
},
afterRender: (userAgent, url, content) => {
// do something
}
}))
When Nginx received a request, it will check it is crawler or not. If it is crawler, it will forward to prerender service (such as pppr). Otherwise it will forward to web server.
I have a page, I want to prerender it.
Ah, pppr.