prerender

Type:
<boolean> | <string>

Default: false
Values:
'auto' | true | false
It sets how the content over the target url should be fetched.
  • CLI
  • JavaScript
  • Shell
  • Python
  • Ruby
const mql = require('@microlink/mql')

const { status, data } = await mql(
  'https://www.sportsnet.ca/hockey/nhl/leafs-john-tavares-return-new-york-hope-positive',
  { prerender: 'auto' }
)

mql.render(data)
The prerendering is a technique that consists of preloading all the elements of the page as a previous step before a web crawler can see the page correctly. Three values be used there:
  • true: A headless browser will be spawned for getting the content of the site. It could be slower since it will use waitUntil to determinte what browser event to wait until consider content is ready.
  • false: A simple HTTP GET will be performed for getting the content of the site. It's faster, since it doesn't evaluate scripts inside the HTML markup.
  • auto: The service will determine if a site needs to have prerendering enabled to retrieve the content or not.
You are going to be interested in to use prerendering for a bunch of reasons; one of them is because a high percentage of internet websites are Single Page Application (SPA).
That means that a major part of the content is built on the client when the user enters in the page, like React, Ember, Angular, etc.
In practice, there is no difference between doing that and being a normal user since both interact using a browser, so prerendering is a better way to simulate a normal user and see the content exactly as he would see it.
However, prerendering have a little trade-off: the cloud-based browser needs to wait until DOM events are done, taking extra time for that. But if you do not do this you will not get the data in any way.
We provided two extra headers for reflecting the decision taken by the service. They are:
  • x-fetch-mode: It determines which fetch technique has been used (being possible 'prerender' or 'fetch' as values).
  • x-fetch-time: It represents the total amount of time spent into the fetch step in a human readable format.
We just recommend to disable prerendering explicitly if you know the target url doesn't need it.
  • CLI
  • JavaScript
  • Shell
  • Python
  • Ruby
const mql = require('@microlink/mql')

const { status, data } = await mql(
  'https://www.sportsnet.ca/hockey/nhl/leafs-john-tavares-return-new-york-hope-positive',
  { prerender: false }
)

mql.render(data)