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 Markdown Response Laravel Package

spatie/laravel-markdown-response

Serve markdown versions of your Laravel HTML pages for AI agents and bots. Detect markdown requests via Accept: text/markdown, known user agents, or .md URLs. Driver-based conversion (local PHP or Cloudflare Workers AI), with caching and HTML preprocessing.

View on GitHub
Deep Wiki
Context7

title: Cache converted responses weight: 2

Converting HTML to markdown on every request would be wasteful, so the package caches results by default. When a cached response exists, it's returned directly without running any controllers or conversion logic.

Caching is enabled with a one-hour TTL out of the box. You can adjust this via environment variables:

MARKDOWN_RESPONSE_CACHE_ENABLED=true
MARKDOWN_RESPONSE_CACHE_STORE=redis
MARKDOWN_RESPONSE_CACHE_TTL=3600

Set MARKDOWN_RESPONSE_CACHE_STORE to any cache store configured in config/cache.php. When left empty, the default cache store is used.

Understand cache keys

The cache key is generated from the request's host, path, and query string. Common tracking parameters like utm_source, gclid, and fbclid are stripped, so https://example.com/about and https://example.com/about?utm_source=google share the same cached response.

URLs ending in .md share the same cache key as their non-suffixed counterpart. So /about.md and /about (with Accept: text/markdown) hit the same cache entry.

You can customize the list of ignored parameters in the config file:

// config/markdown-response.php

'cache' => [
    'ignored_query_parameters' => [
        'utm_source',
        'utm_medium',
        'utm_campaign',
        // ...
    ],
],

Clear the cache

You can clear the markdown cache with an artisan command:

php artisan markdown-response:clear

Note: this flushes the entire configured cache store. If you're using a shared cache store, consider using a dedicated store for markdown responses.

Customize cache key generation

If the default cache key strategy doesn't fit your needs, you can extend the GeneratesCacheKey class and point to it in the config:

// config/markdown-response.php

'cache' => [
    'key_generator' => App\Actions\CustomCacheKey::class,
],
namespace App\Actions;

use Illuminate\Http\Request;
use Spatie\MarkdownResponse\Actions\GeneratesCacheKey;

class CustomCacheKey extends GeneratesCacheKey
{
    public function __invoke(Request $request): string
    {
        return 'markdown-response:' . hash('xxh128', $request->fullUrl());
    }
}
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