Use Prerender to improve AngularJS SEO

Nuget Package of ASP.NET MVC HttpModule for prerender.io: Install-Package DotNetOpen.PrerenderModule

Source Code of ASP.NET MVC and ASP.NET Core Middlewares for prerender.io:  https://github.com/dingyuliang/prerender-dotnet  (ASP.NET Core middleware is still in progress, not check in yet.)

There are a lot of good JavaScript framework (i.e. AngularJS, BackboneJS, ReactJS) which have been released recent years, and they become more and more popular. Many companies and developers are using them to develop applications. There are a lot of advantages we use these frameworks:

  • Separate frontend development and backend development.
  • JavaScript Framework + Restful API (Or Microservice architecture) is very flexible and easy to maintain, we can use the same set API for ourselves and our clients.
  • Very light weight backend, compared with tranditional MVC framework, i.e. ASP.NET MVC, Spring MVC, ...
  • Help to improve development productivity.

The challenge of using JavaScript framework heavily, especially on user facing pages (not administration pages), is that we use virtual elements or attributes and JavaScript binding JSON object, is not SEO friendly.Many search engines, social medias' crawlers even don't support to crawl/index JavaScript pages.

The good thing is that we can use PreRender.io to prerender page (which will execute the JavaScript on page) before it renders to search engine crawlers.

What is Prerender

Prerender.io is developed via Node.js, it allows your javascript apps to be crawled perfectly by search engines, social medias, and it is compatible with all JavaScript frameworks and libraries. It uses PhantomJS to render a javascript-rendered page as HTML. Also, we can implement cache on prerender service layer, which will be much better for performance.

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

There are many prerender middlewares in different languages (middleware is the library which we can use it to implement prerender logic inside application):

The fulllist of prerender middleware is: https://prerender.io/documentation/install-middleware. Apache and Nginx are server container level middleware, others are application level middleware.

The official website is: https://prerender.io/. The github url: https://github.com/prerender

What are Prerender solutions

Generally, we have 3 different solutions to implement with prerender.io

  • Option 1: Application Level

Implement prerender.io logic on application level by using middlewares (i.e. NodeJS Express middleware, Ruby on Rails middleware, ASP.NET MVC middleware, ...)

  • Request comes in
  • Application will check if the request comes from crawlers (based on user agent information) or not.
  • If request comes from crawlers, then appliaction will call prerender service with original URL as query string.
    • Prerender service will call application
    • Application returns the original HTML with JavaScript logic to prerender service
    • Prerender service will execute JavaScript inside HTML, similar with browser
    • Prerender service will return the final HTML to application.
    • Appliaction will return the final HTML to browser.
  • If request comes from regular users, application will execute the output and send back to browsers.

  • Option 2: Server Container Level

Implement prerender.io logic on Server container level. (i.e. Apache, Nginx, IIS) by using URL rewrite middlewares.

  • Request comes in
  • Server container (i.e. Apache, Nginx, IIS) will check if the request comes from crawlers (based on user agent information) or not.
  • If request comes from crawlers, then rewrite URL (with original URL as query string) to prerender service.
    • Prerender service will call application
    • Application returns the original HTML with JavaScript logic
    • Prerender service will execute JavaScript inside HTML, similar with browser
    • Prerender service will return the final HTML to server container (i.e. Apache, Nginx, IIS).
  • If request comes from regular users, then redirects traffic to application as normal. Application will execute and return output to server container.

  • Option 3: Network Level

Implement prerender.io logic on network level, by using load balance proxy, i.e. HA Proxy:

  • Request comes in
  • Load balance Proxy will check if the request comes from crawlers (based on user agent information) or not.
  • If request comes from crawlers, then redirects traffic (with original URL as query string) to prerender service.
    • Prerender service will call application
    • Application returns the original HTML with JavaScript logic
    • Prerender service will execute JavaScript inside HTML, similar with browser
    • Prerender service will return the final HTML to load balance proxy.
  • If request comes from regular users, then redirects traffic to application. Application will execute and return output to load balance proxy.

Solution comparison

Above 3 different solutions are solving the same problems on different levels, but they turns out different performance results.

  • Option 1: Application Level

This solution is easy to be implemented, and easy to debug, but it also makes application heavy, as application needs to wait prerender service call application and execute JavaScript, this will take a lot of time, depends on how complicated the JavaScript logic it is. So, the bottleneck of this solution will be the application. The requests will be stuck on application level, server container level, and network level.

If prerender service is down, it will affect regular user access experience (long-time request to prerender service, consume resource on both application and server container).

  • Option 2: Server Container Level

This solution leverages URL rewrite logic to move the bottleneck from application level to IIS level, at least, for application itself, it will be easier to be extended, and it's flexible on application level. The requests will be stuck on server container level, network level.

If prerender service is down, it will affect regular user access experience either (long-time request to prerender service, consume resource on server container).

  • Option 3: Network Level

This solution will be implemented on highest level, on network level by using load balance, so, there is no bottleneck on server container and application, as it moves to load balance.

With this solution, even prerender service is down,  it will not affect regular user access experience.

Based on above basic analysis, generally speaking, Option 3 is better than Option 2, Option 2 is better than Option 1.

Performance Concerns

Whatever which solution we will use, we should still think about how to improve performance, as executing JavaScript will take longer time than server side. On the other hand, since we only redirect the crawlers' traffic to prerender service, we don't need to provide the exactly up-to-date information for crawlers, I think we should use cache in prerender service to improve the performance, even we can cache 1 day. :)

Next post, I will explain how to implement prerender service by using the opensource project: https://github.com/prerender

Use Prerender to improve AngularJS SEO的更多相关文章

  1. Prerender.io - 预渲染架构,提高AngularJS SEO

    近些年来,越来越多的JavaScript框架(即AngularJS,BackboneJS,ReactJS)变得越来越流行.许多公司和开发人员使用这些JavaScript框架开发应用程序.这些框架有很多 ...

  2. Prerender Application Level Middleware - ASP.NET HttpModule

    In the previous post Use Prerender to improve AngularJS SEO, I have explained different solutions at ...

  3. Prerender Application Level Middleware - ASP.NET Core Middleware

    In the previous post Use Prerender to improve AngularJS SEO, I have explained different solutions at ...

  4. 【翻译】ExtJS vs AngularJS

    原文:ExtJS vs AngularJS ExtJS和AngularJS是两个行业内领先的富界面开发框架.TechFerry有机会使用Ext JS和Angular JS来开发多个富界面的单页面应用程 ...

  5. splinter(python操作浏览器魔魁啊)

    from splinter import Browser def main(): browser = Browser() browser.visit('http://google.com') brow ...

  6. Splinter常用API介绍(转)

    # Example from splinter import Browser with Browser() as browser: # Visit URL url = "http://www ...

  7. Python splinter 环境搭建

    今天无意间看到了splinter. Splinter是一个使用Python开发的开源Web应用测试工具.它可以帮你实现自动浏览站点和与其进行交互. Splinter对已有的自动化工具(如:Seleni ...

  8. 单页面应用SPA和多页面应用MPA

    单页面应用(SinglePage Web Application,SPA) 只有一张Web页面的应用,是一种从Web服务器加载的富客户端,单页面跳转仅刷新局部资源 ,公共资源(js.css等)仅需加载 ...

  9. WHAT IS THE DIFFERENCE BETWEEN REACT.JS AND REACT NATIVE?

    Amit Ashwini - 09 SEPTEMBER 2017 React.js was developed by Facebook to address its need for a dynami ...

随机推荐

  1. 将Web项目访问的URL项目名设置为"/"

    工具:Eclipse 步骤: 1.鼠标右键项目名--->properties--->Web Project Setting--->Context root. 将Context roo ...

  2. 不小心删掉root目录......

    1.先保存还剩下的的东西,比如说桌面的文件,保存在/下面其他目录 2.执行命令 cp -R /etc/skel/.[!.]* ./ 3.reboot

  3. JOSN反串行化

    JOSN编码的数据可以使用eval函数生产操作的类型. <%@ Page Language="C#" %> <!DOCTYPE html PUBLIC " ...

  4. Codeforces#355

    大小号刷题,大号,被查重,悲剧,最后小号过了3题 A题: 分析:大于h的+2,小于等于h的+1 #include <iostream> #include <cstdio> #i ...

  5. Android SQLite总结[转载]

    [转载] :http://blog.163.com/zqy216_2008/blog/static/4119371820119954812509/ 最近在做的项目涉及到了SQLite,大学时没有好好学 ...

  6. 火狐上的一个post提交工具(主要用于测试接口时候)

    添加的过程 安装完后,就可以在下图上,看到一个poster 点击poster就可以看到下图 图中红线圈好的,是必须要填写的 Url是访问路径 Name是参数名称 Value是参数值 需要注意一点的是: ...

  7. UIAlertController 自定义输入框及KVO监听

    UIAlertController极大的灵活性意味着您不必拘泥于内置样式.以前我们只能在默认视图.文本框视图.密码框视图.登录和密码输入框视图中选择,现在我们可以向对话框中添加任意数目的UITextF ...

  8. 在PHP语言中使用JSON

      目前,JSON已经成为最流行的数据交换格式之一,各大网站的API几乎都支持它. 我写过一篇<数据类型和JSON格式>,探讨它的设计思想.今天,我想总结一下PHP语言对它的支持,这是开发 ...

  9. Node.js timer的优化故事

    前几天nodejs发布了新版本4.0,其中涉及到一个更新比较多的模块,那就是下面要介绍的timer模块. timers: Improved timer performance from porting ...

  10. UVa 412 - Pi

    题目大意:给定一种估算Pi的方法:给出一系列随机数,从中任选两个数,这两个数的最大公约数不大于1(互质)的概率为6/(Pi*Pi),然后给出一系列数,据此估算Pi的值.直接模拟就好了. #includ ...