How to do Facebook Open Graph friendly meta tags with client-side template engines like AngularJS, Mustache, Handlebars

前端 未结 3 1459
自闭症患者
自闭症患者 2020-12-10 07:20

According to my testing, Facebook\'s crawlers do not render client-side templates like a browser.

I want to avoid a webserver and building HTML files for Open Graph

相关标签:
3条回答
  • 2020-12-10 07:41

    When you think about it it should be clear, why this does not work.

    The Facebook crawler downloads the HTML as it is served by the server. The Facebook crawler will not execute any JavaScript, like all the crawler will not execute the JavaScript. This is due to security restrictions and for speed reason (they do not have the time execute JavaScript on their servers.)

    There is no way around this. If you want the crawler to index you page, you need to give them directly what you want them to read.

    Tip: You could use something like phantom.js to render your pages on the server side and serve this to the crawlers.

    0 讨论(0)
  • 2020-12-10 07:41

    Use the ?_escaped_fragment_ method along with a prerender service. Facebook will respect the same crawlable Ajax specification as Google. Please see https://developers.google.com/webmasters/ajax-crawling/docs/specification

    0 讨论(0)
  • 2020-12-10 07:49

    The solution is basically to use some kind of server-side user-agent detection to pick up whenever a social media crawler arrives.

    0 讨论(0)
提交回复
热议问题