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

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:

```js
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:

```js
fetch(url).catch(console.error)
```

### Bash

You could have something like this:

```bash
#!/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:

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

### Manually

Just go the URLs 🤷‍♂️

- https://www.google.com/webmasters/sitemaps/ping?sitemap=https://clubmate.fi/sitemap.xml
- https://www.bing.com/ping?sitemap=https://clubmate.fi/sitemap.xml.

Or [use Google Search Console](https://search.google.com/) to submit the
sitemaps:

![Screenshot of Google Search Console](/images/sitemap-submit-ui-of-google-search-console.png)

Or [Bing Webmaster Tools](https://www.bing.com/webmasters/homepage):

![Screenshot of Bing Webmaster Tools](/images/sitemap-submit-ui-of-bing-webmaster-tools.png)

## 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.
