clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Ping your sitemaps to Google and Bing to inform search engines about new content

Filed under: Webdev— Tagged with: seo

You can tell Google or Bing about the changes that have happened in your site, by pinging them your changed sitemaps.

"Pinging" in this case means sending a GET request to a provided endpoint. So nothing magical there.

Where to ping?

Let’s say your site’s domain is the classic example.com, in that case you would send a GET request to a URL looking something like this:

  • Google: https://www.google.com/webmasters/sitemaps/ping?sitemap=https://example.com/sitemap.xml
  • Bing: https://www.bing.com/ping?sitemap=https://example.com/sitemap.xml

How to ping?

Of course this up to your project, but here’s some ideas.

Axios

Here’s an example how to do the GET request using the popular Axios http client. Note that we don’t need to wait for the requests, since we don’t care about the response:

const pingSearchEngines = sitemap => {
  const google = `https://www.google.com/webmasters/sitemaps/ping?sitemap=https://example.com/${sitemap}`
  const bing = `https://www.bing.com/ping?sitemap=https://example.com/${sitemap}`

  axios.get(google).catch(console.log)
  axios.get(bing).catch(console.log)
}

Fetch

Fetch is pretty much the same:

fetch(url).catch(console.log)

Bash

You could have something like this:

#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

curl -S -s -o /dev/null "https://www.google.com/webmasters/sitemaps/ping?sitemap="$1
curl -S -s -o /dev/null "https://www.bing.com/ping?sitemap="$1
echo "Sitemaps pinged"

This -S -s -o /dev/null makes curl silent, but prints errors.

Usage:

$ ping.sh https://clubmate.fi/sitemap.xml

Manually

Just go the URLs 🤷‍♂️

Or use Google Search Console to submit the sitemaps:

Screenshot of Google Search Console

Or Bing Webmaster Tools:

Screenshot of Bing Webmaster Tools

How often to ping?

Google doesn’t define a limit. For example on a site I’m working, we have a 30 minute cache for the sitemaps, so we ping every 30 minutes. The request is inside the code that created the sitemaps, so it runs when the cache expires, either on its own or when a deployment happens.

Comments would go here, but the commenting system isn’t ready yet, sorry. Tweet me @hiljaa if you want to make a correction etc.

  • © 2021 Antti Hiljá
  • About
  • Follow me in Twatter → @hiljaa
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!