How using .bind() in your Meteor app can screw up your SEO entirely

I was crestfallen when I discovered that my article on calculus was no longer in the second page of Google’s result for “Calculus explained”. Perhaps the search engine’s algorithm no longer saw as high of value in my article as it used to. Or maybe Google, being Google, was again trying to encourage me to publish stuff more often on the rather empty site of mine. (That article used to be at the second page when one searches the term calculus. A day later it was at the 12th page.)

It didn’t take long before my face contorted in horror as I discovered that my articles were nowhere to be found in Google Search. That could be the reason why traffic to my site had been in a state of decline the past two weeks.

This was what would look like when one searched the article’s URL:

As we can see from the Type Error above, the function .bind() is undefined. After some googling, I learnt that hantomJS doesn’t have .bind() for functions.

The way SEO works in a Meteor application is that we need to have the meta tag <meta name=”fragment” content=”!”> in every page (normally added in by spiderable), which tells the crawler to visit ?_escaped_fragment_= version of the page. So the crawler would get to crawl a static version of the page rendered by PhantomJS .

This is because when one first visits a Meteor website, dynamically generated meta tags (such as the meta description tag for an article) would only be created after the article entry is loaded into the minimongo database in the browser (a MongoDB emulator).

more detail on what happens when you first visit a page of a Meteor app

So when .bind() is used in your meteor app, PhantomJS panics, throws in a Type Error and screws your SEO up.

To avoid this, we just need to switch to using underscorejs’s _.bind(), which basically works the same except that the syntax is slightly different: instead of having it like object.function.bind(this), we have

_.bind(object.function, this)

Fortunately my website doesn’t really have much content to start with. The decline in traffic caused by this is rather insignificant comparing to the decline in traffic causes by not writing and publishing articles on a regular basis:

So the moral of the story is:

the only way to maintain a humongous amount of traffic is to keep writing great stuff, or stuff with clickbait headline (and hope that it works).