Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX Crawling with Express on static routes

I have a static route for

/public/slides/lecture1.html#!3

which displays the third div element (other div HTMLelements will have display:none;) of lecture1.html.

I use Express app.use(express.static(WEBROOT)); and everything works fine. But I want to be able to make that slide AJAX Crawable so I want to react on request which looks like this:

/public/slides/lecture1.html?_escaped_fragment_=3

and return single page with only that one div element - so that Google would index texts from slide 3 in lecture1.html properly.

How do I do that using Express?

Is it possible to add GET request handler on link which is already served by express.static?

Thanks

like image 326
bubersson Avatar asked Nov 27 '25 13:11

bubersson


1 Answers

Check out https://github.com/OptimalBits/Crawlme. It is an express middleware that handles this automatically. Just do this and you're ajax-crawlable:

var
  express = require('express'),
  http = require('http'),
  crawlme = require('crawlme');

var app = express()
  .use(crawlme())
  .use(express.static(__dirname + '/webroot'));

http.createServer(app).listen(80);
like image 94
Arokor Avatar answered Nov 30 '25 00:11

Arokor