Angular2 SEO-如何使Angle 2应用程序可爬网 [英] Angular2 SEO - How to make an angular 2 app crawlable

查看:94
本文介绍了Angular2 SEO-如何使Angle 2应用程序可爬网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular-Meteor框架构建Angular 2应用.

I am building an Angular 2 app using the Angular-Meteor framework.

我希望通过Google和其他搜索引擎实现快速一致的索引,并允许Facebook分享者和其他抓取工具生成我的JS生成内容的预览.

I would like to achieve fast and consistent indexing by google and other search engines, and allow Facebook sharer and other scrapers to generate previews of my JS-generated content.

通常,SPA使用PhantomJS在服务器端呈现页面并将静态HTML发送给客户端.

Usually SPAs use the PhantomJS to render the page server-side and send the static HTML to the client.

当然,当我拦截_escaped_fragment_或看到google或scraper用户代理时,我可以自己生成PhantomJS,但是当直接在流量大的网站上直接生成PhantomJS时,我总是会遇到内存泄漏和孤立的Phantom实例.和此模块).

Of course I can spawn PhantomJS myself when I intercept an _escaped_fragment_ or when I see the google or scraper user agent, but I always experienced memory leaks and orphan Phantom instances when spawning PhantomJS directly on websites with a big traffic (I used NodeJS and this module ).

对于Angular 1应用程序,我曾经使用 Angular-SEO 之类的角度模块来解决此问题,但似乎很难将该模块转换为角度2.

For Angular 1 apps, I used to solve this with angular modules like Angular-SEO, but it seems hard to convert such module to angular 2.

我还没有找到合适的 Angular 2 模块.到今天为止,我应该自己构建它,还是有其他好的方法来实现这一目标?

I did not find any appropriate Angular 2 module for this yet. Should I build it myself, or is there any other good way to achieve this as of today ?

推荐答案

关于Angular2的妙处在于,启动后,根应用程序元素中的所有内容都会消失.这意味着您可以将想要的任何东西从爬虫要拾取的服务器放到那里.

The great thing about Angular2 is that when fired up, all content inside your root app-element goes away. This means that you can put whatever you want in there from the server which you want to be picked up by crawlers.

您可以在应用中使用服务器呈现的内容版本来生成此内容,或者具有自定义逻辑.

You can generate this content by using a server-rendered version of the content in your app, or have custom logic.

您可以在此处找到更多信息: https://angularu.com/VideoSession/2015sf/angular -2-服务器渲染 此处: https://github.com/angular/universal

You can find some more information here: https://angularu.com/VideoSession/2015sf/angular-2-server-rendering and here: https://github.com/angular/universal

这篇关于Angular2 SEO-如何使Angle 2应用程序可爬网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆