skip to Main Content

I’d like to create a site with Angular (I’m new), but also want to be able to have different “views” be cachable in the search engines and have their own URL routes. How would I achieve this with Angular, or is best not to use it?

2

Answers


  1. Enable pushState in Angular with $locationProvider.html5Mode(true); so that you have real URLs and make sure that, when the URL is requested by the client, you deliver the complete page for that URL from the server (and not a set of empty templates that you populate with JS).

    When a link is followed, you’ll go through an Angular view and update the existing DOM (while changing the URL with pushState) but the initial load should be a complete page.

    This does mean duplicating effort (you need client and server side versions of the code for building each page). Isomorphic JS is popular for dealing with that issue.

    Login or Signup to reply.
  2. If you want to expose Angular views to search engines and other bots, I suggest using an open source framework that we developed at Say Media. It uses node.js to render the pages on the server when it detects a bot vs a real user. You can find it here:

    https://github.com/saymedia/angularjs-server

    I would suggest not using different routes, however, as most search engines will penalize you for having duplicate content on multiple urls. And while you might think they would just hit the bot version of your site, they are getting more sophisticated about crawling single page app like sites. I would be cautious about duplicate routes for the same content.

    Good Luck!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search