DEV Community

Dicky Saputra
Dicky Saputra

Posted on

How to Make Rank Math Sitemap Pages Load Faster

One common issue on WordPress websites with a large number of posts is that the Rank Math XML Sitemap can become slow to load. This happens because the sitemap is generated dynamically every time a visitor or search engine bot requests it.

A simple solution is to use a static sitemap cache, allowing the web server to serve pre-generated XML files directly without executing PHP for every request. This significantly reduces server load and improves crawling performance.

Benefits of Using a Static Sitemap

Using a static sitemap cache provides several advantages:

  • Faster sitemap loading times.
  • Lower CPU and PHP worker usage.
  • Improved crawling efficiency for Google and other search engines.
  • Ideal for websites with thousands or even millions of URLs.
  • Reduced server load when search engine bots frequently request sitemap files.

1. Setting RankMath Sitemap Cache

The first step is to enable static sitemap generation using the Rank Math Sitemap Tweak plugin.

The plugin automatically creates static copies of your XML sitemaps and stores them in the following directory:

/wp-content/uploads/rank-math/
Enter fullscreen mode Exit fullscreen mode

Instead of generating the sitemap dynamically through WordPress, your web server can serve these static files directly.

2. Configure Apache (.htaccess)

If your website is running on Apache, add the following rules to your .htaccess file.

# ==========================
# XML cache
# ==========================
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP:Cookie} !wordpress_logged_in
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads/rank-math/%{HTTP_HOST}%{REQUEST_URI} -f
RewriteRule ^(.*)$ /wp-content/uploads/rank-math/%{HTTP_HOST}/$1 [L]
Enter fullscreen mode Exit fullscreen mode

These rules check whether a cached sitemap file exists. If it does, Apache serves the static file immediately without loading WordPress.

3. Configure Nginx

If your server is using Nginx, add the following configuration inside your server block.

#
# Static cache
#
location / {

    try_files \
        /wp-content/uploads/rank-math/$host$uri \
        $uri \
        $uri/ \
        @wordpress;

    autoindex on;
}

#
# WordPress
#
location @wordpress {
    rewrite ^ /index.php?$args last;
}
Enter fullscreen mode Exit fullscreen mode

With this configuration, Nginx will always try to serve the cached sitemap first. If the file does not exist, the request is passed to WordPress as usual.

How It Works

The process is straightforward:

  1. The plugin generates static XML sitemap files.
  2. The files are stored in the wp-content/uploads/rank-math/ directory.
  3. When Google or another search engine requests a sitemap, the web server checks whether the cached file exists.
  4. If it exists, the server serves the static file immediately.
  5. If not, the request is forwarded to WordPress, which generates the sitemap dynamically.

This approach dramatically reduces response time while minimizing PHP execution and server resource usage.

Conclusion

Using a Static Sitemap Cache for Rank Math is a highly recommended optimization, especially for websites with a large amount of content.

By combining a static sitemap cache plugin with either Apache (.htaccess) or Nginx configuration, your XML sitemaps can be served directly as static files. This results in faster sitemap delivery, lower server resource consumption, and improved crawling efficiency for search engines.

Top comments (0)