Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@hangarlabs/web-prerender

0.0.5 • Public • Published

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

  1. Node v10.16.3 LTS or higher https://nodejs.org/en/.
  2. TypeScript https://www.typescriptlang.org/.
  3. TS Lint https://palantir.github.io/tslint/.
  4. 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 corporate@thehangar.cr Report any issue here: https://github.com/hangarlabs/web-prerender/issues

Install

npm i @hangarlabs/web-prerender

DownloadsWeekly Downloads

0

Version

0.0.5

License

MIT

Unpacked Size

29.5 kB

Total Files

16

Last publish

Collaborators

  • avatar
  • avatar
  • avatar