Usage#

Use Case 1: server-side render all traffic#

  • Implementation 1: forward all traffic to service.prerender.cloud
    • This is the default implementation of our libraries and so service.prerender.cloud has a 3 minute cache to help mitigate the time cost of prerendering a request
  • Implementation 2: forward all traffic to service.prerender.cloud but use a local cache
    • This is the recommended implementation because it's quick to implement and high performance (because you're not adding the round trip cost to service.prerender.cloud to 100% of your requests), and easy to do with our Node middleware but more involved for Apache, Nginx, and others
  • Implementation 3: build all HTML in a batch process instead of forwarding traffic to service.prerender.cloud
    • This is the most cost effective and performant implementation but the most challenging.
      • use implementation 2 and crawl the pages with a user-agent that would trigger the prerender
      • or curl service.prerender.cloud/http://example.com > my-prerendered-page.html

Use Case 2: server-side render bot traffic only#

  • Same as use case 1 but restricted to certain user-agents (not recommended due to potential cloaking penalties and the fact that HTTP caches become low value since user-agents are high cardinality)

Use Case 3: Scrape meta or open graph tags of a JavaScript app#

  • Use any HTTP library in any language to do something like:

    const fetch = require("fetch").fetchUrl;
    const fs = require("fs");
    const cheerio = require("cheerio");
    
    const urlsToParse = ["https://www.prerender.cloud"];
    
    const options = {
      headers: {
        // put your token here or you'll be rate limited
        "x-prerender-token": ""
      }
    };
    
    function fetchUrl(url) {
      return new Promise(function(res, rej) {
        fetch(
          `http://service.prerender.cloud/${url}`,
          options,
          (error, meta, body) => {
            if (error) {
              console.error("error fetching", url, error);
              return null;
            }
    
            let parsed = cheerio.load(body.toString());
    
            return res([url, parsed("meta").toArray().map(m => m.attribs)]);
          }
        );
      });
    }
    
    Promise.all(urlsToParse.map(fetchUrl)).then(urls => {
      fs.writeFile("urlsMeta.json", JSON.stringify(urls));
    });
    
Hosted on Roast.io