Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using node.js to serve content from a Backbone.js app to search crawlers for SEO

Either my google-fu has failed me or there really aren't too many people doing this yet. As you know, Backbone.js has an achilles heel--it cannot serve the html it renders to page crawlers such as googlebot because they do not run JavaScript (although given that its Google with their resources, V8 engine, and the sobering fact that JavaScript applications are on the rise, I expect this to someday happen). I'm aware that Google has a hashbang workaround policy but it's simply a bad idea. Plus, I'm using PushState. This is an extremely important issue for me and I would expect it to be for others as well. SEO is something that cannot be ignored and thus cannot be considered for many applications out there that require or depend on it.

Enter node.js. I'm only just starting to get into this craze but it seems possible to have the same Backbone.js app that exists on the client be on the server holding hands with node.js. node.js would then be able to serve html rendered from the Backbone.js app to page crawlers. It seems feasible but I'm looking for someone who is more experienced with node.js or even better, someone who has actually done this, to advise me on this.

What steps do I need to take to allow me to use node.js to serve my Backbone.js app to web crawlers? Also, my Backbone app consumes an API that is written in Rails which I think would make this less of a headache.

EDIT: I failed to mention that I already have a production app written in Backbone.js. I'm looking to apply this technique to that app.

like image 298
axsuul Avatar asked Sep 16 '12 09:09

axsuul


People also ask

Is Node JS good for SEO?

It consequently accelerates how quickly the crawlers index your sites. Since you got a fair idea of how to hire Node js developers & its frameworks or libraries can help improve SEO, we shall dive into the best Node. js SEO libraries for SEO-friendly web development in 2022!

Can Google crawl JavaScript links?

As early as 2008, Google was successfully crawling JavaScript, but probably in a limited fashion. Today, it's clear that Google has not only evolved what types of JavaScript they crawl and index, but they've made significant strides in rendering complete web pages (especially in the last 12-18 months).

Can Nodejs used in browser?

js is a server-side JavaScript run-time environment. It's open-source, including Google's V8 engine, libuv for cross-platform compatibility, and a core library. Notably, Node. js does not expose a global "window" object, since it does not run within a browser.

Does Google Search Use JavaScript?

While Google Search runs JavaScript with an evergreen version of Chromium, there are a few things that you can optimize. This guide describes how Google Search processes JavaScript and best practices for improving JavaScript web apps for Google Search.


1 Answers

First of all, let me add a disclaimer that I think this use of node.js is a bad idea. Second disclaimer: I've done similar hacks, but just for the purpose of automated testing, not crawlers.

With that out of the way, let's go. If you intend to run your client-side app on server, you'll need to recreate the browser environment on your server:

  1. Most obviously, you're missing the DOM (Document Object Model) - basically the AST on top of your parsed HTML document. The node.js solution for this is jsdom.

  2. That however will not suffice. Your browser also exposes BOM (Browser Object Model) - access to browser features like, for example, history.pushState. This is where it gets tricky. There are two options: you can try to bend phantomjs or casperjs to run your app and then scrape the HTML off it. It's fragile since you're running a huge full WebKit browser with the UI parts sawed off.

  3. The other option is Zombie - which is lightweight re-implementation of browser features in Javascript. According to the page it supports pushState, but my experience is that the browser emulation is far from complete - however give it a try and see how far you get.

like image 191
zzen Avatar answered Sep 28 '22 08:09

zzen