定制 prerender/laravel-prerender 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prerender/laravel-prerender

Composer 安装命令:

composer require prerender/laravel-prerender

包简介

Laravel middleware for prerendering JavaScript-rendered pages via Prerender.io

README 文档

README

Laravel middleware for Prerender.io. Intercepts requests from bots and crawlers and serves prerendered HTML, so your JavaScript-rendered app is fully indexable by search engines and social media scrapers.

Compatible with Laravel 11+ and PHP 8.2+.

Installation

composer require prerender/laravel-prerender

Publish the config file:

php artisan vendor:publish --tag=prerender-config

Setup

Add your token to .env:

PRERENDER_TOKEN=your-token

The middleware registers itself automatically via the service provider.

Configuration

Key Env var Default Description
enable PRERENDER_ENABLE true Disable entirely (e.g. local dev)
prerender_url PRERENDER_SERVICE_URL https://service.prerender.io Service URL (override for self-hosted)
prerender_token PRERENDER_TOKEN null Your Prerender.io token
prerender_soft_http_codes PRERENDER_SOFT_HTTP_STATUS_CODES true Pass 3xx/404 codes through as-is
full_url PRERENDER_FULL_URL false Send full URL including query string
timeout PRERENDER_TIMEOUT 0 Guzzle timeout in seconds (0 = none)

Whitelist / Blacklist

Only prerender URLs matching the whitelist (empty = all URLs pass):

'whitelist' => ['/blog/*', '/product/*'],

Never prerender URLs matching the blacklist (static assets are blacklisted by default):

'blacklist' => ['*.js', '*.css', '/admin/*'],

Patterns support * wildcards. Blacklist patterns are matched with the query string stripped, so *.woff2 also matches /font.woff2?v=3.

How it works

Requests are prerendered when all of the following are true:

  • The HTTP method is GET
  • The User-Agent matches a known bot/crawler (Googlebot, Bingbot, Twitterbot, GPTBot, ClaudeBot, etc.)
    — OR the URL contains _escaped_fragment_
    — OR the X-BUFFERBOT header is present
  • The URI is not blacklisted (static assets are excluded by default)
  • The URI matches the whitelist (if configured)

If the Prerender service is unreachable, the middleware falls back gracefully.

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固