How to make Angularjs application crawalable

前端 未结 5 1915
醉话见心
醉话见心 2021-02-05 20:31

Im building single page app using Angular.js, My question is how to make application crawlable because routing is handled using ng-view on client side and server just return si

5条回答
  •  庸人自扰
    2021-02-05 20:50

    The only working solution I know is the one the core AngularJS team uses for its documentation website.

    • First they use HTML5 history for URLs and a fallback with a hashbang. URLs with a hashbang make Google crawl them with _escaped_fragment_ in the query string.
    • Then they use AngularJS string interpolation and directives on the backend to render the templates as they will be in the DOM when the user loads the page and AngularJS parses it.
    • They pass that to Google and thus they have the same content in the search index as in the users' browsers (so this is not cloaking).

    This was mentioned by the core developers in the AngularJS Google group. [1] [2] [3]

    Also from the rest of the threads there I think they are using PhantomJS and NodeJS to parse the pages.

    [1] https://groups.google.com/d/msg/angular/yClOeqR5DGc/4YXGx9z8EpAJ

    [2] https://groups.google.com/d/msg/angular/EGwg49uAmMI/j-kj9nytT-IJ

    [3] https://groups.google.com/d/msg/angular/EGwg49uAmMI/j-kj9nytT-IJ

提交回复
热议问题