alexui's avatar

How to generate Sitemap XML with Pagination in Laravel?

Hi, hope everyone is doing well. I'm looking for a way or a laravel package that allows Pagination in XML Sitemaps.

How is data (URL) for posts stored?

  • In the Database, we have the column for post slug, title, etc.

Right now, I am using Laravel View to output an XML Page with all the URLs but the problem is that the website has over 15,000 posts which makes the page too laggy and slow to load and I suspect that it'll be harder for Search Engines to crawl as well.

0 likes
2 replies
Braunson's avatar
Braunson
Best Answer
Level 18

Either generate a custom XML sitemap for your site or use a package like spatie/laravel-sitemap along with caching.

I would suggest looking into leveraging sitemap indexes as there is a limit to a sitemap.

Google Sitemap guidelines suggest you break up large sitemaps into smaller sitmaps as a single sitemap can contain up to 50k URLs and must not exceed 50MB uncompressed. As a solution use a sitemap index file to list all the individual sitemaps and submit this single file to Google rather than submitting individual sitemaps.

More general sitemap guidelines at https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap

1 like
alexui's avatar

@Braunson Perfect! Thank you. I ended up creating a custom XML Sitemap (Counting Post numbers and then using dynamic routes to manage the sitemap urls).

Please or to participate in this conversation.