@hangarlabs/web-prerender
v0.0.5
Published
Works as a middleware to prerender JS generated websites built on React.js or Angular.js.
Downloads
2
Readme
web-prerender
This package caches a pre-rendered version of an URL using Puppeteer and Redis.
Nowadays we have websites that are JS generated and the search engine crawling bots cannot fetch the metadata causing bad SEO results, so with this package you can serve a pre-rendered version of the websites with all required metadata.
Requirements
- Node v10.16.3 LTS or higher https://nodejs.org/en/.
- TypeScript https://www.typescriptlang.org/.
- TS Lint https://palantir.github.io/tslint/.
- Redis Client https://www.npmjs.com/package/redis.
How to install the package
Check the required Node.js version with
nvm use
Install with NPM or Yarn
npm install or yarn install
Usage TypeScript
Usage with NPM or Yarn
npm install @hangarlabs/web-prerender --save
or
yarn add @hangarlabs/web-prerender
import { IOptionsPreRenderQueue, Ssr } from "web";
const prerender = new Ssr({
redisDatabase: parseInt(env.redis.db, 10),
redisHost : env.redis.host,
redisPort : env.redis.port as number,
} as IOptionsPreRenderQueue);
Create a RedisClient ...
[https://www.npmjs.com/package/redis](https://www.npmjs.com/package/redis)
prerender
.setRedisCache(RedisClient)
.initHandlerBull()
.preRender()
const url = "https://www.google.com";
const {html, ttRenderMs} = await prerender.ssr(url);
Using Express.js you can something like this:
if (html) {
response.set("Server-Timing", `Prerender;dur=${ttRenderMs};desc="Headless render time (ms)"`);
return response.status(200)
.send(html);
}
Develop
Develop with NPM or Yarn
npm run dev yarn dev
Build
Build with NPM or Yarn
npm run build or yarn build
Test
Build with NPM or Yarn
npm run test or yarn test
Contact
Hangar Corporate Team [email protected] Report any issue here: https://github.com/hangarlabs/web-prerender/issues