How to build a sitemap

A sitemap is very important if you want to search engines discover and index your site properly. Your site is a jungle of HTML, CSS and JavaScript files so the more you make it easier for search engines, the better. A sitemap.xml file is one of the most and easiests way to implement.

No matter the language you are using in your site, this is the right way to create a sitemap.

A sitemap is a file that search engines like Google Bot can understand to index your site. This file contains all the links to your pages in a special (but not so complicated) format.

It contains also an important information: how often you update that specific page. This way the bot will visit periodically to index the new changes.

The Sitemap protocol format consists of XML tags. All data values in a Sitemap must be entity-escaped. The file itself must be UTF-8 encoded.

https://www.sitemaps.org/protocol.html

Let see an example of a sitemap.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2020-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset> 

The above sitemap only contains one page: the home page. Maybe that’s ok because your site only contains a landing page but let see how do we build a sitemap with more pages.

If you have more pages to index you will write a new block:

<url>
   <loc>http://www.example.com/catalog?item=12&desc=vacation_hawaii</loc>
   <changefreq>weekly</changefreq>
</url>

Typically you sitemap XML file will be hosted at the root of your domain: http://www.mysite.com/sitemap.xml.

For instance, you can see the site map of javaniceday.com here: https://javaniceday.com/sitemap.xml

sitemap.xml sample

If you are using WordPress or any other CMS, probably you will have several plugins to generate your sitemap.xml with one click and (automatically) every time you create new content. Otherwise you will have to create an algorithm by your own.

See an implementation in Node.js here:
https://javaniceday.com/2019/11/19/how-to-build-a-sitemap-xml-in-node-js-using-express/

Maybe you also are interested in

Photo by Jilbert Ebrahimi on Unsplash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s