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 automatically by crawling your site or building them manually. Add URLs, models, lastmod/changefreq/priority, images and alternates, then write to file or disk. Supports sitemap index and large sites.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • SEO & Crawlability: The package excels in automating sitemap generation, aligning with Laravel’s SEO and discoverability needs. It supports both automated crawling (discovering URLs dynamically) and manual URL injection (explicit control over sitemap content).
  • Modularity: Leverages Laravel’s service container and dependency injection, making it easy to integrate with existing workflows (e.g., scheduled tasks, event-driven updates).
  • Extensibility: Supports custom crawler profiles, URL filtering, and model-based sitemap generation (Sitemapable interface), enabling tailored implementations for complex architectures.
  • Multi-format Support: Handles sitemap indexes, alternate language URLs, and Google News tags, catering to internationalization and niche use cases.

Integration Feasibility

  • Laravel Native: Designed for Laravel (v8+), with zero configuration required beyond composer require. Leverages Laravel’s filesystem, queues, and scheduling systems.
  • Crawler Dependencies: Relies on spatie/crawler (included) and optionally spatie/browsershot (for JS rendering). Minimal external dependencies beyond core Laravel.
  • Database Agnostic: Works with any Eloquent models or static routes, avoiding tight coupling to specific database schemas.
  • Cloud/Storage Compatibility: Supports writing sitemaps to local disks, S3, or other Laravel-supported storage, with visibility controls for public/private files.

Technical Risk

  • Crawl Performance: Automated crawling may introduce high resource usage (CPU/memory) for large sites. Mitigated via:
    • Configurable concurrency (default: 10 threads).
    • Depth limits and max crawl counts.
    • Filtering rules to exclude irrelevant URLs.
  • Dynamic Content: JS-rendered content (via browsershot) adds complexity and latency. Requires Chrome installation and may fail in headless environments (e.g., CI/CD).
  • SEO Accuracy: Crawler may miss non-standard routes (e.g., API-generated URLs) or authenticated pages. Requires manual overrides or custom shouldCrawl logic.
  • Scheduling Overhead: Scheduled generation adds cron/queue load. Should be tested under production traffic to avoid timeouts.

Key Questions

  1. Scale Requirements:
    • What’s the expected sitemap size (URLs)? Will automated crawling be feasible, or is manual injection preferred?
    • Are there rate limits (e.g., external APIs) that could block the crawler?
  2. Dynamic Content:
    • Does the site rely heavily on client-side rendering (SPA, JS frameworks)? If so, is browsershot viable, or should URLs be pre-defined?
  3. Performance Impact:
    • How will scheduled crawls interact with Laravel queues or cron jobs? Are there peak hours to avoid?
  4. Customization Needs:
    • Are there non-standard sitemap tags (e.g., video sitemaps) required beyond Google News/alternates?
  5. Monitoring:
    • How will crawl failures (e.g., 404s, timeouts) be logged/alerted? The package lacks built-in error tracking.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Perfect fit for Laravel apps (v8+). No framework-specific hacks required.
  • Storage Systems: Compatible with Laravel’s filesystem drivers (local, S3, FTP, etc.), enabling seamless deployment to cloud storage.
  • Task Scheduling: Integrates natively with Laravel’s Schedule facade for periodic regeneration.
  • Queue Support: Can be adapted to run asynchronously (e.g., via Laravel Queues) to avoid blocking HTTP requests.

Migration Path

  1. Pilot Phase:
    • Start with manual sitemap generation (e.g., Sitemap::create()->add(Url::create(...))) for critical paths (e.g., blog posts, product pages).
    • Validate output against Google Search Console for accuracy.
  2. Crawler Rollout:
    • Gradually introduce automated crawling for static routes, using SitemapGenerator::create().
    • Configure filters (shouldCrawl, hasCrawled) to exclude non-essential pages (e.g., admin, login).
  3. Dynamic Content:
    • If JS rendering is needed, install spatie/browsershot and test in a staging environment with execute_javascript = true.
  4. Scheduling:
    • Implement a scheduled command (sitemap:generate) with incremental updates (e.g., daily or post-deployment).
    • Monitor crawl duration and adjust concurrency/depth as needed.

Compatibility

  • Laravel Versions: Officially supports Laravel 8+. Tested with PHP 8.0+.
  • Dependency Conflicts: Minimal risk; spatie/crawler and browsershot are well-maintained.
  • Non-Laravel PHP: Can be used in vanilla PHP, but loses Laravel-specific features (e.g., filesystem disks, scheduling).

Sequencing

  1. Installation:
    composer require spatie/laravel-sitemap
    php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
    
  2. Configuration:
    • Adjust config/sitemap.php for crawler settings (e.g., execute_javascript, chrome_binary_path).
    • Set up storage disk (e.g., public, s3) for sitemap output.
  3. Development:
    • Implement manual URLs for critical pages.
    • Test crawler with SitemapGenerator::create()->writeToFile().
  4. Production:
    • Deploy scheduled command (sitemap:generate).
    • Set up monitoring for crawl failures (e.g., Laravel Horizon for queue jobs).
  5. Optimization:
    • Profile crawl performance and adjust concurrency/depth.
    • Add custom logic (e.g., Sitemapable interface) for dynamic models.

Operational Impact

Maintenance

  • Low Overhead: Minimal maintenance once configured. Updates are infrequent (package is stable).
  • Configuration Drift: Risk of misconfigured crawler rules (e.g., excluding critical pages). Mitigate with:
    • Documentation of shouldCrawl/hasCrawled logic.
    • Unit tests for sitemap generation.
  • Dependency Updates: Monitor spatie/crawler and browsershot for breaking changes (e.g., Chrome version requirements).

Support

  • Troubleshooting:
    • Crawl Failures: Logs may be sparse; consider wrapping SitemapGenerator in a service with custom logging.
    • JS Rendering: browsershot issues (e.g., Chrome crashes) require system-level debugging.
  • Community: Active GitHub repo (2.6k stars) with responsive maintainers. Documentation is comprehensive.
  • Enterprise Support: Spatie offers paid support for critical issues (e.g., security vulnerabilities).

Scaling

  • Horizontal Scaling:
    • Crawler runs in a single process; not distributed. For massive sites, consider:
      • Pre-defined URLs instead of crawling.
      • Incremental crawls (e.g., crawl new content only).
  • Vertical Scaling:
    • Increase concurrency or server resources for large sites.
    • Offload to a separate queue worker to avoid blocking requests.
  • Storage:
    • Sitemap indexes can grow large; ensure storage system (e.g., S3) supports high read throughput.

Failure Modes

Failure Scenario Impact Mitigation
Crawler times out on large site Incomplete sitemap Set setMaximumCrawlCount, monitor duration.
JS rendering fails (browsershot) Missed dynamic URLs Fallback to manual URLs or disable JS crawling.
Storage write permissions denied Sitemap not published Verify disk visibility settings.
Scheduled job skips Stale sitemap Use Laravel’s withoutOverlapping for reliability.
External links return 404s Broken URLs in sitemap Filter out non-200 responses in hasCrawled.

Ramp-Up

  • Developer Onboarding:
    • 1–2 hours to understand basics (manual URLs, crawler config).
    • Half-day to implement custom logic (e.g., Sitemapable interface).
  • SEO Team Training:
    • Explain how sitemaps are generated and where to validate output (Google Search Console).
  • DevOps:
    • Ensure Chrome is installed for JS rendering (if used).
    • Configure storage permissions for sitemap files.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport