Install the Node.js middleware

To use SEO.js with a Node.js app install the express-seojs package:

$ npm install express-seojs --save

Configure your API key

In the initialization section of your app invoke the middleware. (Replace YOUR_API_KEY with your real API key that you got when signing up)

var seojs = require('express-seojs');
app.use(seojs('YOUR_API_KEY'));

Alternatively, if you prefer to keep credentials separate from code you can set the SEOJS_TOKEN environment variable and leave it empty in the code: app.use(seojs());

After this your app.js should look something like this:

var express = require('express');
var app = express();

var seojs = require('express-seojs');
app.use(seojs('YOUR_API_KEY'));

app.get('/', function(req, res){
  res.send('hello world');
});

app.listen(3000);

Requests to your app containing the _escaped_fragment_ query parameter will now be forwarded to our CDN.

Enable AJAX crawling

To tell search engine crawlers that your site allows AJAX crawling you need to add the fragment meta tag to your HTML header.

<head>
  <meta name="fragment" content="!">
  ...
</head>

Use compatible URLs

Your URLs need to be in one of these formats:

  • /nice#!page - they are Hashbang URLs
  • /nice/page - they are HTML5 PushState URLs

Hashbang URLs are easier to implement and are compatible with older browsers, but many users find PushState URLs look more convenient.

Hash fragment URLs without the exclamation mark cannot be crawled:

  • /one#page needs to be changed to /one#!page or /one/page