Angular SEO方案
1、如果是java web项目,可以直接使用AngularSEO Filter。
官网地址 :http://www.angularseo.net/#about
<filter> <filter-name>SEOFilter</filter-name> <display-name>SEOFilter</display-name> <description>AngularSEO Filter</description> <filter-class>net.angularseo.SEOFilter</filter-class> <!-- The path to the PhantomJS binary --> <init-param> <param-name>phantomjs.binary.path</param-name> <param-value>C:\\phantomjs2.0\\bin\\phantomjs.exe</param-value> </init-param> <!-- The time waiting the JS page to finish the dynamic loading, unit is second. --> <init-param> <param-name>waitForPageLoad</param-name> <param-value>3</param-value> </init-param> <!-- Filter already embed google, bing, baidu UserAgent keywords, If you want to support more, add them and split with | --> <init-param> <param-name>robotUserAgents</param-name> <param-value>YodaoBot|Zealbot</param-value> </init-param> <!-- The interval that SEOFilter update the static page snapshot --> <init-param> <param-name>cacheTimeout</param-name> <param-value>24</param-value> </init-param> <!-- The path to save the static version pages --> <init-param> <param-name>cachePath</param-name> <param-value>c:\\cache</param-value> </init-param> <!-- crawlDepth is used to limited the crawl depth --> <init-param> <param-name>crawlDepth</param-name> <param-value>10</param-value> </init-param> <!-- The default page encoding of this site --> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>SEOFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
关于phantomjs: http://phantomjs.org/
2、后台针对每一个需要SEO的页面分别写一套,在后台渲染生成html的代码,嵌入到前台的html中,但是不显示。
<div style="display:none"> ///后台生成的专门为了SEO需要的代码 //在后台可以通过判断请求的agent参数,判断是否是搜索引擎爬虫,如果不是,不需要生成这段隐藏的代码。 </div> <div ng-app="XXApp" ng-controller="XXController"> //前台业务的代码 </div>