doukengsha9472 2015-07-21 19:00
浏览 53

AngularJS和SEOing

I'm working on a small Angular application, and I'm about midway through with a mind breaking issue. It's common knowledge that SEO spiders/crawlers tend to not use Javascript, hence all META data must be loaded during server load. I'm trying to create a very dynamic base, that I can reuse for future projects.

My application is being built using LAMP, I'm not against Node but I must use PHP/MySQL for this particular project. I have a main configuration document 'config.json', and via the main index page I'm loading it in before HTML rendering to set all important META data. Now, I'm then loading the same configuration file in my Angular application using 'http.get(...)'. I just feel as if there's absolutely no need to load the same file twice.

I can solve this issue by setting the configuration via a script on the main page like so,

<?php

   $config_plain = file_get_contents( './app/data/config.json', FILE_USE_INCLUDE_PATH );
   $config = json_decode( $config_plain );
       // #    set config for meta data on load

?>
<!DOCTYPE HTML>
<html ng-app="foobar" ng-controller="dataCtrl">
   <head>
      <title ng-bind="page.title"><?php echo $config->title; ?></title>
      <meta name="description" content="<?php echo $config->meta->description; ?>">
      ...
      <script>
         angular.module('foobar', [...])
            .controller('dataCtrl', ['$rootScope', function($rootScope) {
               $rootScope.config = <?php echo $config_plain; ?>;
                  $rootScope.page = {  };
                  $rootScope.page.title = $rootScope.config.brand;

                    //    # set config for data binding
            }])

            .service('page', ['$rootScope', function($rootScope) {
                return {
                    title: function(route) {
                        $rootScope.page.title = $rootScope.config.brand + ' | ' + route;
                            // #    update page title dynamically
                    }
                };
            }]);
      </script>
   </head>
</html>

Which would alternatively be,

<?php

   $config_plain = file_get_contents( './app/data/config.json', FILE_USE_INCLUDE_PATH );
   $config = json_decode( $config_plain );
       // #    set config for meta data on load

?>
<!DOCTYPE HTML>
<html ng-app="foobar" ng-controller="dataCtrl">
   <head>
      <title ng-bind="page.title"><?php echo $config->title; ?></title>
      <meta name="description" content="<?php echo $config->meta->description; ?>">
      ...
      <script>
         angular.module('foobar', [...])
            .controller('dataCtrl', ['$rootScope', function($rootScope) {
               $http.get('/app/data/config.json')
                  .success(function(response) {
                      $rootScope.config = response;
                          $rootScope.page = {  };
                          $rootScope.page.title = $rootScope.config.brand;
                            // #    set config for data binding
                   });
            }])

            .service('page', ['$rootScope', function($rootScope) {
                return {
                    title: function(route) {
                        $rootScope.page.title = $rootScope.config.brand + ' | ' + route;
                            // #    update page title dynamically
                    }
                };
            }]);
      </script>
   </head>
</html>

Though this all kind of seems really messy.

My actual question is, how would I go about SEOing application content dynamically using both angular and php?

  • 写回答

1条回答 默认 最新

  • douyue8685 2015-07-21 23:08
    关注

    Almost four years ago Matt Cutts said:

    Googlebot keeps getting smarter. Now has the ability to execute AJAX/JS > to index some dynamic comments http://goo.gl/F9et1

    Here is google's official blogpost if you have detailed questions. http://googlewebmastercentral.blogspot.com/2011/11/get-post-and-safely-surfacing-more-of.html

    I honestly think you'll be fine. Test it. Tweet your experiment page, so that the page gets indexed and go from there. As for the other search engines (Yahoo and Bing) I think they won't be able to do this for a while, if ever.

    Note: MC's comments were about JS based comments not entire pages but I can't find the link of G's others developments to understanding JS. I know it's much more advanced now.

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端