Posts Learn Components Snippets Categories Tags 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

24 views

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.
<?php

/* 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
];

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More