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 in automating sitemap generation, aligning with Laravel’s ecosystem and addressing a critical SEO need (dynamic URL discovery, structured sitemap formatting). It integrates seamlessly with Laravel’s routing, models, and caching systems.
  • Hybrid Approach: Supports both automated crawling (discovering URLs via SitemapGenerator) and manual control (explicit Url definitions), offering flexibility for complex sites (e.g., dynamic content + static pages).
  • Extensibility: Leverages Laravel’s service container and events (e.g., Sitemapable interface) for custom logic, enabling integration with existing model-based workflows (e.g., Eloquent models).
  • Multi-Sitemap Support: Built-in SitemapIndex for large sites (e.g., segmented by content type) and compliance with Google’s sitemap size limits.

Integration Feasibility

  • Laravel Native: Zero-config setup (auto-registers via service provider) with optional config publishing. Minimal boilerplate for basic use cases.
  • Crawler Customization: Fine-grained control over crawling behavior (depth, concurrency, URL filtering) via closures or config, reducing risk of over-crawling or missing critical pages.
  • Storage Agnostic: Supports filesystem disks (local, S3, etc.) and public visibility flags, aligning with modern Laravel deployment patterns (e.g., Vapor, Forge).
  • JavaScript Rendering: Optional headless Chrome integration (spatie/browsershot) for SPAs or JS-heavy sites, though adds complexity (dependency management, performance overhead).

Technical Risk

  • Crawling Scalability: High-concurrency crawls (default: 10) may strain server resources or trigger rate-limiting. Mitigation: Configure setConcurrency() and setMaximumCrawlCount().
  • Dynamic Content: Crawler may miss URLs loaded via AJAX or client-side routing (e.g., React/Vue). Mitigation: Enable JS execution or manually add critical routes.
  • Model Integration: Sitemapable interface requires model modifications, which may conflict with existing logic or migrations. Mitigation: Use trait-based implementations or middleware.
  • SEO Pitfalls: Incorrect lastmod dates or missing priority/changefreq tags could hurt rankings. Mitigation: Validate sitemap output and use manual overrides where needed.
  • Dependency Bloat: Optional browsershot adds ~50MB to deployment (Chrome binary). Mitigation: Only enable for JS-heavy sites.

Key Questions

  1. Use Case Priority:
    • Is the primary goal automated discovery (crawling) or manual control (explicit URLs)?
    • Are there JS-rendered pages requiring headless Chrome?
  2. Performance Constraints:
    • What are the server resources (CPU/memory) and crawl time SLAs?
    • Should crawling be rate-limited or scheduled (e.g., off-peak)?
  3. SEO Requirements:
    • Are there multilingual or news/article sitemap needs?
    • Do URLs require custom metadata (e.g., priority, changefreq)?
  4. Deployment Model:
    • Is the sitemap stored in S3/CDN or local filesystem?
    • Are there public visibility requirements for sitemap files?
  5. Maintenance:
    • Who will validate sitemap accuracy post-deployment?
    • How will changes to routes/models be reflected in the sitemap?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for Laravel’s routing (route() helpers), Eloquent models, and filesystem disks. Complements packages like spatie/backups (for sitemap archiving) or spatie/laravel-activitylog (for tracking sitemap changes).
  • PHP Version: Compatible with Laravel 8+ (PHP 8.0+), with backward compatibility for older versions.
  • Testing: Integrates with Laravel’s testing tools (e.g., mocking SitemapGenerator in unit tests).
  • CI/CD: Supports scheduled generation via Laravel’s task scheduling, enabling CI/CD pipelines to trigger updates.

Migration Path

  1. Pilot Phase:
    • Start with manual sitemap generation (explicit Url definitions) for critical pages (e.g., /about, /blog).
    • Validate output using Google’s Sitemap Tester.
  2. Crawler Rollout:
    • Gradually introduce automated crawling for less critical sections (e.g., blog archives).
    • Use shouldCrawl() to exclude non-essential pages (e.g., /admin, /webhooks).
  3. Advanced Features:
    • Enable JS execution only for SPAs or dynamic content.
    • Implement multi-sitemap indexing for large sites (e.g., /posts-sitemap.xml, /pages-sitemap.xml).
  4. Monitoring:
    • Log crawl errors and sitemap generation failures (e.g., via Laravel’s logging or Sentry).
    • Set up health checks for sitemap accessibility (e.g., ping /sitemap.xml).

Compatibility

  • Laravel Versions: Tested on Laravel 8–11; minor version bumps may require dependency updates.
  • PHP Extensions: Requires cURL, DOM, and fileinfo extensions (standard in Laravel).
  • Database: No direct DB dependencies, but model-based sitemaps rely on Eloquent.
  • Caching: Leverages Laravel’s cache (e.g., cache()->remember()) for performance; configure config/sitemap.php if needed.

Sequencing

  1. Setup:
    • Install package: composer require spatie/laravel-sitemap.
    • Publish config: php artisan vendor:publish --tag=sitemap-config.
  2. Basic Implementation:
    • Generate a sitemap for a single route:
      SitemapGenerator::create(url('/'))->writeToFile(public_path('sitemap.xml'));
      
  3. Model Integration:
    • Implement Sitemapable for Eloquent models (e.g., Post):
      class Post implements Sitemapable {
          public function toSitemapTag(): Url { ... }
      }
      
  4. Crawler Customization:
    • Configure depth, concurrency, and filters in config/sitemap.php or via closures.
  5. Automation:
    • Schedule generation in routes/console.php:
      Schedule::command('sitemap:generate')->daily();
      
  6. Advanced:
    • Add alternates/news tags, enable JS execution, or split into multiple sitemaps.

Operational Impact

Maintenance

  • Configuration Drift: Centralized config (config/sitemap.php) reduces drift risk, but changes require redeployment.
  • Model Changes: Adding/removing Sitemapable models may break sitemap generation if not validated.
  • Crawler Updates: Underlying spatie/crawler updates may alter crawling behavior; test after major versions.
  • Dependency Updates: Optional browsershot requires Chrome binary updates; automate via CI/CD.

Support

  • Debugging:
    • Use SitemapGenerator::debug() to log crawled URLs and errors.
    • Check Laravel logs for crawler timeouts or HTTP errors.
  • Common Issues:
    • Crawl Timeouts: Increase guzzle_options timeouts or reduce concurrency.
    • Duplicate URLs: Use hasCrawled() to deduplicate or filter.
    • Missing URLs: Manually add critical routes or adjust crawl depth.
  • Documentation: Comprehensive Spatie docs and GitHub issues provide solutions for edge cases.

Scaling

  • Large Sites:
    • Split into multiple sitemaps (e.g., by content type) and use SitemapIndex.
    • Incremental crawling: Use setMaximumCrawlCount() to limit load.
  • Performance:
    • Cache sitemaps (e.g., cache()->remember()) to avoid regenerated on every request.
    • Offload generation to a queue worker (e.g., sitemap:generate command in queue).
  • Distributed Systems:
    • For microservices, generate sitemaps per-service and merge via SitemapIndex.

Failure Modes

Failure Scenario Impact Mitigation
Crawler times out Incomplete sitemap Increase timeouts, reduce concurrency
JS execution fails Missed client-side URLs Fallback to manual URL addition
Model toSitemapTag() errors Broken sitemap links Validate models, use try-catch in implementation
Storage permission issues
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony