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 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛