Posts Learn Components Snippets Categories Tags Tools About

How to Generate Gzip Compressed XML Sitemaps in Laravel

Learn how to generate gzip compressed XML sitemap in Laravel to optimize the file size

Created on Jul 28, 2021


To generate a Gzip Sitemap in Laravel you can make use Laravelium/Sitemap package. If you have not read our tutorial on How to Automatically Generate Sitemap on Laravel? then do give it a read for a full step-by-step guide.

Publish Sitemap Configuration
To generate Gzip sitemap you will have to publish the sitemap configuration.
php artisan vendor:publish --provider="Laravelium\Sitemap\SitemapServiceProvider"

Update Sitemap Configuration
Now you can update whether to use the Gzip compression or not from the config from "sitemap.php" file. Set the "use_gzip" configuration to "true" and now when you generate the sitemap you will have it in "gzip" format.

/* Simple configuration file for Laravel Sitemap package */
return [
    'use_cache' => false,
    'cache_key' => 'laravel-sitemap.'.config('app.url'),
    'cache_duration' => 3600,
    'escaping' => true,
    'use_limit_size' => false,
    'max_size' => null,
    'use_styles' => true,
    'styles_location' => '/vendor/sitemap/styles/',
    'use_gzip' => true

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️