Configuring the crawler | laravel-sitemap-go | Spatie       

 SPATIE  

laravel-sitemap-go
==================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap-go](https://spatie.be/docs/laravel-sitemap-go/v1)  Customizing-the-crawler  Configuring the crawler

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-sitemap-go/v1) 

  Configuring the crawler    
- [ Introduction ](https://spatie.be/docs/laravel-sitemap-go/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sitemap-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-sitemap-go/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-sitemap-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-sitemap-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-sitemap-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-sitemap-go/v1/support-us)
- [ About us ](https://spatie.be/docs/laravel-sitemap-go/v1/about-us)

Creating sitemaps
-----------------

- [ Generating a sitemap ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/generating-a-sitemap)
- [ Manually creating a sitemap ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/manually-creating-a-sitemap)
- [ Creating a sitemap index ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/creating-a-sitemap-index)
- [ Splitting large sitemaps ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/splitting-large-sitemaps)
- [ Grouping URLs into multiple sitemaps ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/grouping-urls-into-multiple-sitemaps)
- [ Adding an XSL stylesheet ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/adding-an-xsl-stylesheet)
- [ Returning a response ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/returning-a-response)
- [ Sorting URLs ](https://spatie.be/docs/laravel-sitemap-go/v1/creating-sitemaps/sorting-urls)

Customizing the crawler
-----------------------

- [ Crawl profiles ](https://spatie.be/docs/laravel-sitemap-go/v1/customizing-the-crawler/crawl-profiles)
- [ Filtering URLs ](https://spatie.be/docs/laravel-sitemap-go/v1/customizing-the-crawler/filtering-urls)
- [ Configuring the crawler ](https://spatie.be/docs/laravel-sitemap-go/v1/customizing-the-crawler/configuring-the-crawler)

Adding content to URLs
----------------------

- [ Alternates ](https://spatie.be/docs/laravel-sitemap-go/v1/adding-content-to-urls/alternates)
- [ Images ](https://spatie.be/docs/laravel-sitemap-go/v1/adding-content-to-urls/images)
- [ Videos ](https://spatie.be/docs/laravel-sitemap-go/v1/adding-content-to-urls/videos)
- [ News ](https://spatie.be/docs/laravel-sitemap-go/v1/adding-content-to-urls/news)
- [ Sitemapable models ](https://spatie.be/docs/laravel-sitemap-go/v1/adding-content-to-urls/sitemapable-models)

Advanced usage
--------------

- [ Scheduled generation ](https://spatie.be/docs/laravel-sitemap-go/v1/advanced-usage/scheduled-generation)
- [ Writing to disks ](https://spatie.be/docs/laravel-sitemap-go/v1/advanced-usage/writing-to-disks)

 Configuring the crawler
=======================

###  On this page 

1. [ Limiting the amount of pages crawled ](#content-limiting-the-amount-of-pages-crawled)
2. [ Setting the crawl concurrency ](#content-setting-the-crawl-concurrency)
3. [ Controlling the crawl depth ](#content-controlling-the-crawl-depth)
4. [ Executing JavaScript ](#content-executing-javascript)

The crawler itself can be [configured](https://github.com/spatie/crawler-go#usage) to do a few different things.

You can configure the crawler used by the sitemap generator, for example, to ignore robot checks:

```
err := sitemap.NewGenerator("https://example.com").
    ConfigureCrawler(func(cfg *crawler.Config) {
        cfg.IgnoreRobots = true
    }).
    WriteToFile(ctx, sitemapPath)
```

Import `github.com/spatie/crawler-go` as `crawler`. Callbacks receive the crawler's configuration before it is validated and started. They can replace HTTP clients, headers, profiles, parsers, queues and observers. The sitemap collector is appended after your callbacks so replacing observers does not remove sitemap generation.

In Laravel applications, set `sitemap.Config.ConfigureCrawler` in your package registration callback for application-wide defaults. Generator defaults are applied first, followed by application configuration and then per-generator `ConfigureCrawler` callbacks. `ShouldCrawl` is combined with the resulting profile.

Limiting the amount of pages crawled
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can limit the amount of pages crawled by calling `SetMaximumCrawlCount`:

```
err := sitemap.NewGenerator("https://example.com").
    SetMaximumCrawlCount(500).
    WriteToFile(ctx, sitemapPath)
```

The default is unlimited. Zero crawls no pages. Negative values return an error. This limits processed crawl requests, including failures, rather than the number of output tags returned by `HasCrawled`.

Setting the crawl concurrency
-----------------------------------------------------------------------------------------------------------------------------------------------

You can set the number of concurrent connections the crawler will use:

```
err := sitemap.NewGenerator("https://example.com").
    SetConcurrency(1).
    WriteToFile(ctx, sitemapPath)
```

The default concurrency is 10. Values below one return an error.

Controlling the crawl depth
-----------------------------------------------------------------------------------------------------------------------------------------

You can limit how deep the crawler follows links:

```
err := sitemap.NewGenerator("https://example.com").
    ConfigureCrawler(func(cfg *crawler.Config) {
        cfg.MaxDepth = 3
    }).
    WriteToFile(ctx, path)
```

Executing JavaScript
--------------------------------------------------------------------------------------------------------------------

The sitemap generator can discover links that are generated by JavaScript when you provide a `crawler.Renderer`. Set `cfg.Renderer` through `ConfigureCrawler`. A renderer implements `Render(context.Context, string) ([]byte, error)` and returns rendered HTML. `crawler.RendererFunc` adapts a function to that interface.

Crawler Go does not bundle Browsershot or a local Chrome executable. Provide your own browser integration or use its `CloudflareRenderer` with your account and credentials. Configure the browser or rendering service outside this package. PHP's `execute_javascript` and `chrome_binary_path` settings do not apply to Go.

Robots checks remain enabled unless explicitly disabled. Only crawl sites you are authorized to access. Custom HTTP clients and renderers are responsible for their network access policy.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
