Integrating Prerender.io with AngularJs web app

Updating or building web app with rich user experience through AngularJs is an easy solution to implement especially if the web app is created for internal use and search engines are irrelevant. Surely, the approach provides the optimal results within the minimum time frame. What if the intended audience is public, and indexing the website is critical for the business; he solution could backfire if special attention is not paid in regard to make website crawlable.

Unlike browsers, Search engine crawlers and bots from various social media websites like Facebook, Twitter, LinkedIn etc, capture indexable information from HTML page itself and they can’t execute JavaScript which is the base of providing rich user experience. So, to assist them we need to complement a way so that they could read all required META or required HTML Tags (TITLE/H1/H2/H3…) which are tailored dynamically.

Running JavaScript on server side and serving the pre-rendered HTML containing all indexable information is the way out to address this issue. Prerender.io is one such free service that helps making it possible.

prerender
prerender

Pre-requisite for Prerender.io

It relies on implementing a URL strategy that have either of below approach:

  • Hash Bang (#!) URLs In case your current url strategy include hash (#) based URLs, change it to Hash Bang URLs.
  • HTML5 Push State

Integration

In order to integrate the Prerender.io make sure below steps are configured on web server or code:

    1. Add below META Fragment tag to page header:
    2. Make sure below modules are enable on your Apache web server:
    3. Prerender Request Token is properly added to the HEADER through web server:
    4. Add below Redirect configuration to help crawlers know the way to fetch the HTML version though Prerender.io:

      Make sure the above rules are not conflicting with any other rules in your web server configuration. Prefer adding them on top of your .htaccess file.

Testing

We can test is configuration done for prerender.io through number of ways like:

Checking view source with query string: _escaped_fragment_

  1. Let say URL of the webpage is http://www.example.com/#!/about
  2. Open the URL in browser and view source.
  3. You won’t find any Meta information & HTML tags dynamically added to webpage rather AngularJs code intact.
  4. Now update the URL with _escaped_fragment_ as query string parameter like http://www.example.com?_escaped_fragment_=/about and view source.
  5. You will now see changes to Meta information & HTML tags being reflected on the webpage and are now pre-served as part of HTML itself.

Facebook debugger

Another easy way to test the integration is user Facebook Debugger . Just type the URL and fetch the see the results, it should show the dynamically tailored Meta information rather than AngularJs code snippets enclosed in curly brackets like {{Page.Title()}}