Laravel,AngularJS和SEO [英] Laravel, AngularJS and SEO

查看:117
本文介绍了Laravel,AngularJS和SEO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有AngularJS前端和Laravel API后端的应用程序. Laravel后端仅侦听请求,处理请求并返回答案.到目前为止,前端和后端是不同的独立应用程序.我这样做是为了以后能够开发可以使用该API的移动应用程序.我还使用JWT来验证用户身份,因此我根本不使用Laravel的会话.此时,我只需要一个webapp.我建立了一个使用角度ui路由器的webapp.

I am developing an app with an AngularJS front end and a Laravel API backend. The Laravel backend just listens for requests, process them and returns an answer. Front and back end are different independent apps... so far. I did it in such a way in order to be able to develop a mobile app later on which could consume the API. Im using also JWT to authenticate users, so Im not using Laravel's sessions at all. At this point I only require a webapp. I built a webapp which uses angular ui-router.

到目前为止,一切都很好.前端和后端工作良好.但是,某些前端视图将是公开的,并且需要共享按钮,它们还需要Google索引.

So far so good. The front end and the back end work well. However some of the front end views will be public and require share buttons, they also require to be indexable by Google.

我已经阅读了一些替代方法.

I've read there are some alternatives.

  1. 进行一些破解使用apache mod_rewrite以便为人们提供有角度的应用程序,而其静态版本则由后端直接提供.我认为使用Laravel并不是很难.
  2. 使用Prerender.js.就Im而言,它与选项1几乎完成了相同的工作,但方式更为完整.
  1. Make some hack using the apache mod_rewrite in order to serve the angular app for people and a static version of it served directly by the backend. I think this would not be very difficult using Laravel.
  2. Using Prerender.js. Which as far as Im concerned does pretty much the same job than option 1 but in a more complete manner.

但是我正在考虑使用第三种替代方法.鉴于我现在只需要webapp,并且API可以正常工作,我正在考虑使用Laravel的内置webapp功能.我可以从角度使用控制器,指令和工厂,并让Laravel处理webapp路由.

However I am thinking about using a third alternative. Given that I only require the webapp now and the API is working I am thinking about using Laravel's built-in webapp functionality. I can use the controllers, directives and factories from angular and let Laravel handle the webapp routing.

这样做的优点是,我可以使用Blade渲染元标记(这完全解决了SEO问题),并使用angular和API提供其余内容.

An advantage of this is that I can render the meta tags using Blade (this fixes completely the SEO issues) and serve the rest of the contents using angular and the API.

你们中有人能看到这种解决方案的缺点吗?或者您知道使用angular和Laravel实现SEO的更好方法吗?

Do anyone of you can see drawacks of such a solution or do you know a better way to accomplish SEO purposes using angular and Laravel?

推荐答案

渲染站点:

如果要使其SEO友好,则必须从服务器端呈现页面.但是,是的,如果仅将服务器渲染的页面提供给机器人,该怎么办?对于真正的用户,客户端渲染将起作用.

You will have to render the pages from server side if you want to make it SEO friendly. But yes, what if you serve the server rendered pages to bots only. And for real users client side rendering will work.

了解有关 Rendertron 的信息,它将检测用户代理并相应地为html提供服务.

Read about the Rendertron which will detect the user agent and accordingly serve the html.

元标记:

使用 Sluggable 并将id替换为url中的slug.您可以关注 https://oodavid.com/article/angularjs-meta-tags-管理/

这篇关于Laravel,AngularJS和SEO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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