Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Sitemap Laravel Package

spatie/laravel-sitemap

Generate XML sitemaps for Laravel by crawling your site or building them manually. Add extra URLs, set last-modified dates, and include models via a simple interface. Write sitemaps to disk with a fluent, developer-friendly API.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • SEO & Crawlability: The package excels at automating sitemap generation, aligning with Laravel’s ecosystem and addressing a core SEO need (dynamic URL discovery, last-modified timestamps, and structured data).
  • Hybrid Approach: Supports both automated crawling (via SitemapGenerator) and manual URL injection (via Sitemap/Url), enabling granular control over sitemap content.
  • Model Integration: The Sitemapable interface allows seamless integration with Eloquent models, reducing boilerplate for dynamic content (e.g., blog posts, products).
  • Extensibility: Supports custom crawlers, URL filtering, and JavaScript rendering (via spatie/browsershot), accommodating complex SPAs or client-side-rendered content.

Integration Feasibility

  • Laravel Native: Zero-config setup with Laravel’s service provider; minimal friction for adoption.
  • Dependency Graph:
    • Core: spatie/laravel-sitemap (MIT).
    • Optional: spatie/browsershot (for JS execution), spatie/crawler (under the hood).
    • No breaking changes to existing Laravel features (e.g., routes, middleware).
  • SEO Stack Compatibility:
    • Works alongside laravel-seo or spatie/laravel-newsletter for unified metadata management.
    • Supports Google News sitemaps, alternate language tags, and priority/change-frequency attributes.

Technical Risk

  • Crawl Performance:
    • Concurrency Limits: Default 10 parallel requests may overwhelm low-tier servers; requires tuning (setConcurrency()).
    • Depth/Scale: Crawling deep or large sites risks timeouts or excessive memory usage (mitigate with setMaximumCrawlCount()).
    • Dynamic Content: JS execution adds latency (~2–5x slower) and Chrome dependency (Docker/headless setup required).
  • Edge Cases:
    • Authentication: Crawler ignores auth routes by default; requires custom shouldCrawl() logic.
    • Duplicate URLs: No built-in deduplication for manually added URLs (handle via hasCrawled() filter).
    • Sitemap Indexing: Manual management of sitemap.xml and sitemap-index.xml (use SitemapIndex class for automation).
  • Testing:
    • Mock SitemapGenerator in unit tests using Sitemap::fake() (if available) or dependency injection.

Key Questions

  1. SEO Strategy:
    • Should the sitemap be fully automated (crawl-based) or hybrid (crawl + manual overrides)?
    • Are there excluded routes (e.g., admin, auth) that need explicit filtering?
  2. Performance:
    • What’s the maximum crawl depth/concurrency sustainable for the target environment?
    • Is JavaScript execution required, and is the team prepared for Chrome setup/maintenance?
  3. Deployment:
    • Where will sitemaps be stored? (public_path(), S3, etc.) and how will they be invalidated on updates?
    • Should generation be scheduled (cron) or triggered (e.g., post-deploy hook)?
  4. Monitoring:
    • How will sitemap completeness/accuracy be validated (e.g., Google Search Console, custom checks)?
    • Are there alerts for failed crawls or missing URLs?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • First-Class Citizen: Leverages Laravel’s Service Container, Artisan, and Filesystem (e.g., writeToDisk()).
    • Event-Driven: Can integrate with Model::saved() or Model::deleted() to update sitemaps dynamically.
    • Testing: Compatible with Laravel’s testing tools (e.g., Http::fake() for crawler mocks).
  • SEO Stack:
    • Complements: spatie/laravel-seo (for meta tags), spatie/laravel-newsletter (for content routing).
    • Extends: Can feed into Google Analytics, structured data tools, or CDN pre-warming.
  • Infrastructure:
    • Cloud Storage: Supports S3, GCS, etc., via Laravel’s filesystem drivers.
    • CI/CD: Sitemap generation can be gated to deploy pipelines (e.g., post-merge).

Migration Path

  1. Pilot Phase:
    • Start with manual sitemap generation (e.g., Sitemap::create()->add(...)) for critical routes (e.g., /blog, /products).
    • Validate against existing sitemaps (e.g., diff URLs, check lastmod timestamps).
  2. Crawl Integration:
    • Gradually replace static sitemaps with SitemapGenerator for non-authenticated routes.
    • Use shouldCrawl() to exclude dynamic or sensitive endpoints.
  3. Model Integration:
    • Implement Sitemapable on key models (e.g., Post, Product) to auto-generate URLs.
    • Test with SitemapGenerator::create()->getSitemap()->add($model).
  4. Advanced Features:
    • Enable JavaScript crawling for SPAs (if needed).
    • Add alternate language tags or news sitemaps for multilingual/news sites.
  5. Automation:
    • Schedule generation via Artisan command (e.g., sitemap:generate) or Laravel Forge/Envoyer hooks.
    • Set up webhook triggers (e.g., GitHub Actions) for CI/CD pipelines.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (PHP 8.0+); check composer.json for exact version constraints.
  • PHP Extensions: Requires cURL, DOM, and MBString (standard in Laravel).
  • Database: No direct DB dependencies, but model integration requires Eloquent.
  • Third-Party:
    • Chrome: Only needed for JS execution (spatie/browsershot).
    • Guzzle: Used for HTTP requests (included via spatie/crawler).

Sequencing

Phase Task Dependencies
Discovery Audit existing sitemaps, identify gaps. SEO team input.
Setup Install package, publish config, configure sitemap.php. DevOps for Chrome setup (if needed).
Validation Generate test sitemap, validate against Google Search Console. Existing sitemap for comparison.
Integration Implement Sitemapable on models, add crawler filters. Model definitions.
Automation Schedule generation, set up monitoring. CI/CD pipeline.
Optimization Tune concurrency/depth, add JS crawling if needed. Performance benchmarks.

Operational Impact

Maintenance

  • Configuration:
    • Centralized in config/sitemap.php (e.g., execute_javascript, chrome_binary_path).
    • Dynamic Overrides: Use method chaining (e.g., SitemapGenerator::create()->setConcurrency(5)) for environment-specific settings.
  • Updates:
    • Minimal: Package follows semantic versioning; breaking changes are rare (check CHANGELOG).
    • Dependency Management: Monitor spatie/crawler and spatie/browsershot for updates.
  • Deprecation:
    • No known end-of-life risks; MIT license ensures long-term viability.

Support

  • Troubleshooting:
    • Crawl Failures: Check shouldCrawl() logic, network timeouts, or blocked robots.txt.
    • Missing URLs: Verify hasCrawled() filters or model toSitemapTag() implementations.
    • JS Issues: Ensure Chrome is installed and execute_javascript is configured.
  • Debugging Tools:
    • Logs: Enable Spatie\Crawler\Crawler::debug() for verbose output.
    • Testing: Use Sitemap::fake() (if available) or manually inspect generated XML.
  • Community:
    • GitHub Issues: Active maintainers (Spatie) respond to questions.
    • Documentation: Comprehensive docs with examples.

Scaling

  • Performance Bottlenecks:
    • Crawl Depth: Limit with depth() or setMaximumCrawlCount().
    • Concurrency: Adjust setConcurrency() based on server resources (start with 5–10).
    • Memory: Large sitemaps may require chunking (e.g., split by model type).
  • **Distributed
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai