Question

I have a Meteor site with Iron-Router. When I use Google's webmaster tools and "fetch as Google", it comes up with an empty body.

Reading Google's documentation on how to make the application crawlable, I believe I need to add a meta tag and return a plain html version of the page if the GET parameter ?_escaped_fragment= is sent.

Is there a simple way to do this with Iron-Router? I have tried diverting the browser to a different template if the GET parameter is present, eg:

Router.map(function () {
    this.route('home', {
        path: '/',
        template: 'home',
        onBeforeAction: function () {
            if (this.params['_escaped_fragment']=='') {
                this.route.options.template = 'another_page';
            }
        },
    });
});

However, this just substitutes another template using javascript, which Google won't see either. Is there a way to provide a plain html file if a specific GET parameter is provided?

Was it helpful?

Solution

Add the spiderable package to your project:

meteor add spiderable

This will automatically add the correct <meta> tag to your page, and spiders will be served a PhantomJS-generated version of your site.

Note that the Google Webmaster tools will still show the empty AJAX version of your page in the crawl results, but Google will crawl and index your page correctly. This appears to be a bug in the Webmaster tools. You can verify that the app was successfully crawled by going to your Webmaster tools homepage (where the list of your websites is). Your website should have a screenshot showing what the Google crawler actually saw.

OTHER TIPS

There is a typo:

if (this.params['_escaped_fragment']=='') {

should be

if (this.params['_escaped_fragment_']=='') {

You missed an underscore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top