vlados/laravel-blade-crawler-detect
Composer 安装命令:
composer require vlados/laravel-blade-crawler-detect
包简介
Boost Lighthouse and PageSpeed scores by hiding cookie banners, chat widgets and heavy scripts from crawlers via two Blade directives. Octane-safe.
关键字:
README 文档
README
Two Blade directives that boost your Lighthouse and PageSpeed scores without changing a thing for real users.
Wrap your cookie banner, chat widget, analytics scripts, video embeds and other heavy chrome in @user ... @enduser. Bots like Googlebot, Lighthouse and PageSpeed will skip it entirely; humans see the same experience as before.
@user <script src="https://heavy-chat-widget.com/loader.js" async></script> <cookie-banner></cookie-banner> @enduser
Result: lighter HTML for crawlers, better Core Web Vitals, more crawl budget spent on the content that actually matters — and zero JS or middleware changes.
Why developers reach for this
- Better Lighthouse / PageSpeed scores. Audit tools render the page like a low-power phone. Strip the widgets they don't need and the score climbs.
- Better Core Web Vitals. LCP, INP and CLS all benefit when crawlers stop pulling in chat libraries and consent banners.
- More crawl budget for real content. Googlebot fetches less JS, indexes more pages.
- One-line wrap. No middleware, no service container plumbing, no view composers — just Blade.
- Octane-safe. Reads the user agent per request, so long-running workers don't serve stale data.
- ReDoS-hardened. User-agent input is clamped before any regex runs.
- Up to date. Built on
jaybizzle/crawler-detect(thousands of bots, regularly updated) plus Lighthouse and PageSpeed out of the box.
Install
composer require vlados/laravel-blade-crawler-detect
That's it — the service provider auto-registers. No config file, no migrations, no env vars.
Requires PHP 8.1+ and Laravel 10, 11, 12 or 13.
The two directives
@user — render only for humans
Anything that hurts your audit score, is invisible to bots anyway, or just doesn't need to ship to crawlers.
{{-- Cookie / consent banners --}} @user <x-cookie-consent /> @enduser {{-- Chat widgets, support bubbles --}} @user <script src="https://widget.intercom.io/widget/{{ config('services.intercom.id') }}"></script> @enduser {{-- Heavy analytics / tag managers --}} @user <script async src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script> @enduser {{-- Lazy-mounted Vue / Livewire / Alpine widgets --}} @user <livewire:product-recommendations :product="$product" /> @enduser
@unlessuser — render only for crawlers
Server-render the SEO-friendly equivalent of something you ship as JS to humans.
{{-- Humans get the interactive gallery --}} @user <product-gallery :images="{{ $product->images->toJson() }}" /> @enduser {{-- Crawlers get plain, indexable images --}} @unlessuser @foreach ($product->images as $image) <img src="{{ $image->url }}" alt="{{ $image->alt }}" loading="lazy"> @endforeach @enduser
Real-world wins
Wrap this in @user |
Why it helps |
|---|---|
| Cookie consent banner | Removes ~200ms LCP delay on Lighthouse |
| Intercom / Drift / Zendesk widget | Removes 100-300KB of third-party JS |
| Google Tag Manager / Analytics | Removes blocking script + network round-trip |
| Optimizely / VWO / experimentation SDKs | Removes render-blocking script |
| Hotjar / FullStory / session recording | Removes 50-150KB of third-party JS |
| YouTube / Vimeo iframe embeds | Removes a heavy iframe + its JS |
| Mapbox / Google Maps iframes | Removes a heavy iframe + its tile fetches |
| Carousel / slider libraries | Removes JS + CSS that crawlers don't render |
| Chat triggers, modal openers | Removes interactive chrome bots can't click |
What "crawler" means
Detection is delegated to jaybizzle/crawler-detect, a battle-tested PHP library that ships a regex covering thousands of bots — Googlebot, Bingbot, DuckDuckBot, AhrefsBot, SemrushBot, Applebot, and so on.
This package additionally treats these as crawlers, since they typically run as audits rather than real visits:
Chrome-LighthouseGoogle Page Speed
Want to add your own? You can swap or wrap the CrawlerDetect instance through Laravel's container.
Performance
The crawler regex is compiled once per process (so Octane workers compile it at boot, traditional FPM workers compile it on first hit). Each render only does:
- One
substrto clamp the UA to 2KB. - One
preg_replacefor exclusions. - One
preg_matchagainst the compiled crawler pattern.
No DB queries, no cache lookups, no allocations beyond the strings above.
Octane / Swoole / RoadRunner
Safe by design. The user agent is read from the current request inside the directive's closure, so long-running workers always see the active request's UA — never a stale one cached at boot.
When NOT to use this
This package is a tool for hiding things crawlers don't need (heavy widgets, third-party scripts, modal chrome). It is not a tool for showing crawlers different content than you show users — that's cloaking under Google's spam policies and can earn a manual penalty. Use @unlessuser for SSR-equivalents of things you JS-render for humans, not for keyword stuffing.
Testing
composer test
Changelog
Please see CHANGELOG.
Contributing
Please see CONTRIBUTING.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Vladislav Stoitsov
jaybizzle/crawler-detect— the regex behind this package- All Contributors
License
The MIT License (MIT). Please see License File for more information.
vlados/laravel-blade-crawler-detect 适用场景与选型建议
vlados/laravel-blade-crawler-detect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.09k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「seo」 「crawler」 「bot」 「user-agent」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vlados/laravel-blade-crawler-detect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vlados/laravel-blade-crawler-detect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vlados/laravel-blade-crawler-detect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
A lightweight, dependency free PHP class that acts as wrapper for Crawlbase API
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 5.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-02