How to build a sitemap

Reading Time: 2 minutes


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 easiest ways to implement.

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

What is it?

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 protocol

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. See the protocol:

Example of a sitemap.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">

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:


Typically your sitemap XML file will be hosted at the root of your domain:

For instance, you can see the site map of here:

sitemap image

A sitemap in WordPress

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

Implementation in Node.js

See an implementation in Node.js here:

About the author

Andrés Canavesi
Andrés Canavesi

Software Engineer with 15+ experience in software development, specialized in Salesforce, Java and Node.js.

Join 22 other subscribers

Leave a Reply