Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
891 views
in Technique[技术] by (71.8m points)

angularjs - Making angular crawlable - Beginning of Project

When developing a site in angularJS do you have to worry about web crawlers before you start working on your site, or can you push it off until the site is finished.

I have read that HTML snapshots are a good solution, for instance. If you chose to do this, would you be able to implement it after coding a site, or would you have to create the site based around this kind of functionality.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think it's good to think about the strategy at the beginning of the project and implement it close to the end of the project.

We got the problem in the company I am working at.

In all cases you will need to answer GET requests to endpoints like

...?_escaped_fragment_=/home

when, say Google or Bing, will crawl the page

...#/home

See offical Google documentation for details.

The question is how you will fill the content of the resource

...?_escaped_fragment_=:path

There are differents strategies :

Generate dynamic snapshots with PhantomJS every time a crawler asks for the resource

This consists in spawning a PhantomJS process at runtime, redirecting the content of the generated HTML page to the output and sending it back to the crawler.

I think this is the most transverse and transparent solution if you website has a lot of dynamic crawlable content.

Generate static snapshots with PhantomJS at build time or when hitting the save button of the CMS of the website

This is good if the content of your crawlable content never changes or just from time to time.

Generate static ? equivalent ? content files at dev time or when hitting the save button of the CMS of the website

This is a very cheap solution as it does not involve PhantomJS. This is good if the content is simple and if you can easily write it or generate it from a database.

It is difficult to handle if the content is complicated to retrieve as you will need to duplicate your code (one client side to render Angular views, and one serverside to generate the whole page ? equivalent ? content for crawlers).

I mentioned the PhantomJS solution, but whatever headless (or not if you can afford a display) browser will do the work. You can even imagine being able to render your views server-side without any browser but just running you JS in a NodeJS server for instance.


Also think for the beginning if you will use HTML5 style URLs, or hash, or hashbang URLs. This can be difficult to change once the content is indexed by search engines. I advice hashbang style even if it can be seen as ? ugly ?.*


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...