AngularJS and SEO

2

I have a site made with AngularJS and PHP.

All content that is common between pages is only uploaded once, when the user changes pages only the content of the respective page is loaded (executing the API in PHP that returns a JSON) and its template.

The meta tags "description" and "keywords" change depending on the page, but as I'm not reloading the entire page, this is a problem.

How do I do it? When changing the content of the page I make a script to change the contents of the tags?
Will not this be a problem when it comes to crawling the site?

    
asked by anonymous 15.12.2014 / 13:56

1 answer

4

If you are using views and routing in AngularJS, each routed page must have a controller. This way, you can use the following template to execute something at the moment the view is loaded completely:

/*Estou assumindo que o módulo do controller já está declarado*/
.controller('MeuController', function ($scope) {
  $scope.$on('$viewContentLoaded', function () {
    //Alterar meta tags com jQuery
  });
});

But the biggest problem is that views only change meta tags if they are loaded, so as Search Engines crawlers do not execute JavaScript, the changed tags will not be captured by crawlers; physical pages are needed for this, unfortunately.

After reading the text from this link , I noticed that the crawler Google can read and execute javascript, however, this javascript MUST be on the same page. In short, the link did the following tests:

  • Use of document.write() within <script></script> in a single HTML file = Crawler read.
  • Use of document.write() in a file .js external = Crawler did not read.
  • Use of innerHTML within <script></script> in a single HTML file = Crawler read.
  • Use of innerHTML in a file .js external = Crawler did not read.
  • Using tabs with jQuery = Crawler read, and associated all content with just one page.
  • Using tabs with AJAX = Crawler read, but attached each tab to a page of its own.
  • In general, the best idea is to put in the <meta> tags what you want to be indexed, even if part of what's in the tags is in the views, not the homepage itself.

        
    15.12.2014 / 14:05