How to Improve SEO for a SPA Using a .NET Back-End?
Join the DZone community and get the full member experience.Join For Free
here is an image made by google depicting the setup of how a crawler index ajax crawling scheme enable application using html snapshot and improve search engine optimization (seo).
in your spa replace the hash fragments (e.g. #myform) to hash bang (e.g. #!myform).
for example, replace
www.example.com/index.html#!myform (which could be available to both crawlers and users.)
how do we create different hash bang for different contents in the same url of a spa?
when the crawler see the hash bang (#!) it knows that the site support ajax crawling scheme on it web server. you have to provide the crawler with an html snapshot of this url, so that the crawler sees the content. how will your server know when to return an html snapshot instead of a regular page? the answer is the url that is requested by the crawler: the crawler will modify each ajax url such as
there are two very important reasons why hash bang is necessary:
hash fragments are never (by specification) sent to the server as part of an http request. in other words, the crawler needs some way to let your server know that it wants the content for the url
http://www.example.com/index.html# !myform(as opposed to simply
http://www.example.com/index.html# !myform(that is, the original url!) to the crawler.
when the crawler see the hash bang it replace it with the “_escaped_fragment_” before making the request to the web server to index that page. for example
the web server sees the “_escaped_fragment_” in the url it knows that the request is from a crawler. the web server will then redirect the request to the headless browser to serve html snapshot from the server.
how to create html snapshots on the web server?
if you are a .net developers you could use asp.net mvc with
. create an
if you do not want these headache of creating, maintaining & scaling html snapshot on your web server check out the following online saas,
- brombone is using nodejs, phantomjs, amazon aws sqs, aws ec2, and aws s3. brombone supports sites that use html5 pushstate urls instead of hashbang urls. they do not offer free trial plan, but they offer a no questions ask money back guarantee. if you have any question contact chad deshon (founder of brombone) on email@example.com . check them on out http://www.brombone.com .
- ajaxsnapshots has multiple snapshotting servers on amazon aws which has a java based dispatcher that sends requests on to one of the phantomjs based headless servers. they use amazon aws sqs, aws ec2, aws elb for load balancing and aws s3. they got free trial plan. they also claim that phantomjs script that they run benefits from many modifications they have made to deal with corner cases that trip up naive implementations. if you have any question contact robert dunne (founder of ajaxsnapshots) on firstname.lastname@example.org . robert also wrote a nice summary of which search and social bots are snapshot aware http://blog.ajaxsnapshots.com/2013/11/googles-crawlable-ajax-specification.html . check them out on https://ajaxsnapshots.com .
how to test headless browser content?
it’s highly recommended that you try out your html snapshot mechanism. it’s important to make sure that the headless browser indeed renders the content of your application’s state correctly. surely you’ll want to know what the crawler will see, right? to do this, you can write a small test application and see the output, or you can use a tool such as fetch as googlebot . a .net developers could use nhtmlunit . nhtmlunit is a .net wrapper of htmlunit; a “gui-less browser for java programs”. it allows you to write code to test web applications with a headless, automated browser.
google put the following steps to make your spa crawling,
- indicate to the crawler that your site supports the ajax crawling scheme.
- set up your server to handle requests for urls that contain
- handle pages without hash fragments
- consider updating your sitemap to list the new ajax urls
to see the details implementation of the above steps click guide to ajax crawling for webmasters and developers . you might find making ajax applications crawlable useful too.
in summary, starting with a stateful url such as http://www.example.com/index.html#myform , it could be available to both crawlers and users as http://www.example.com/index.html# !myform which could be crawled as using modern headless browsers, we can easily return the fully rendered content per request by redirecting bots on web servers.
in 2009 google released the idea of
a special thanks to chad deshon (founder of brombone) and robert dunne (founder of ajaxsnapshots) for reviewing this blog.
Published at DZone with permission of Diganta Kumar. See the original article here.
Opinions expressed by DZone contributors are their own.