Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build sitemap.xml for AngularJS website?

I have setup an AngularJS application which is using ui-state router. It has some static pages and other than that it has profile pages which generate dynamic page based on profile id.

For SEO purpose I have used PhantomJS and generate HTMLs to give crawler response.

But, How can I generate sitemap.xml which contains all the dynamic pages URL and by that crawler can fetch and list on search engine?

like image 714
Mayur Champaneria Avatar asked Nov 14 '16 14:11

Mayur Champaneria


People also ask

How do I get an XML sitemap?

Go to SEO > General > Features. Make sure the “XML sitemaps” toggle is on. You should now see your sitemap (or sitemap index) at either yourdomain.com/sitemap.xml or yourdomain.com/sitemap_index.xml.

What is sitemap in angular?

A sitemap is a file that provides search engines data about the pages of your site. If you're using a content management system (CMS), your sitemap needs to be kept up to date as you add new content/pages.


1 Answers

Using JavaScript

You can use XMLWriter to create an XML. Then you can pass this XML as a string to your web server. Check this out for XML Writer.

Here is a tutorial for the available methods for writing an XML using XMLWriter - Tutorial

Using Nodejs

You can write a node js function for generating the sitemap from the generated URLs. Please refer to this link for a sample.

The better way is to create a script in the backend to generate it periodically to update sitemaps. Query the tables, create URLs and generate XML files. You can configure cron jobs in the server to generate the sitemaps periodically.

There will be libraries and tutorials available for each BE technology for generating the sitemap.

For example:

Ruby on Rails - Nokogiri
Elixir - sitemap
.Net - Tutorial
Java - Tutorial
Express JS - express-sitemap

like image 73
Tessy Thomas Avatar answered Oct 12 '22 22:10

Tessy Thomas