定制 snowsoft/laravel-page-speed 二次开发

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

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

snowsoft/laravel-page-speed

Composer 安装命令:

composer require snowsoft/laravel-page-speed

包简介

Laravel Page Speed

README 文档

README

Laravel Page Speed

Latest Version Total Downloads Daily Downloads License GitHub Stars PHP Version

Laravel Page Speed

Laravel Page Speed delivers an end-to-end optimization pipeline for Blade-rendered pages and REST APIs with measurable gains in latency, bandwidth, and resiliency.

Table of Contents

Overview

  • Dual scope: optimizes rendered HTML and JSON/XML payloads without modifying your business payloads.
  • Composable stack: enable only the middleware you need through config/laravel-page-speed.php.
  • Store-agnostic: works with Redis, Memcached, DynamoDB (via cache tags), file, or array drivers across Laravel 10–13.
  • Built for observability: exposes latency, memory usage, cache hits, and circuit status via standard HTTP headers.

Optimization Pipelines

Web (HTML/Blade)

  • Structured HTML minification and comment stripping that stay compatible with Bootstrap, Tailwind, and Livewire.
  • Targeted critical CSS inlining to reduce render-blocking round trips.
  • Script deferral and DNS prefetching that maintain execution order through data-ps-* guards.

APIs (REST/JSON)

  • Adaptive compression (Brotli first, Gzip fallback) with configurable size thresholds to avoid overhead on small payloads.
  • Response caching with method-aware invalidation, dynamic tag derivation per path segment, and hit-rate metrics.
  • Pre-hardened security headers (HSTS, CSP, Permissions-Policy) and an automatic circuit breaker with customizable fallbacks.
  • Lightweight health check middleware designed for Kubernetes probes and service orchestrators.

Quick Integration

Web Middleware

Choose the registration pattern that matches your Laravel install:

Laravel 10.x (app/Http/Kernel.php)

Append the middleware inside the web group so the order stays deterministic:

protected $middlewareGroups = [
    'web' => [
        // ... existing middleware
        \Snowsoft\LaravelPageSpeed\Middleware\InlineCss::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ElideAttributes::class,
        \Snowsoft\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,
        \Snowsoft\LaravelPageSpeed\Middleware\CollapseWhitespace::class,
        \Snowsoft\LaravelPageSpeed\Middleware\DeferJavascript::class,
    ],
];

Laravel 11.x, 12.x and 13.x (bootstrap/app.php)

Use the middleware configurator introduced in Laravel 11. Extend the existing ->withMiddleware closure:

use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: __DIR__.'/../')
    // ... existing configuration
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->appendToGroup('web', [
            \Snowsoft\LaravelPageSpeed\Middleware\InlineCss::class,
            \Snowsoft\LaravelPageSpeed\Middleware\ElideAttributes::class,
            \Snowsoft\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,
            \Snowsoft\LaravelPageSpeed\Middleware\CollapseWhitespace::class,
            \Snowsoft\LaravelPageSpeed\Middleware\DeferJavascript::class,
        ]);

        // keep other group definitions (api, broadcast, etc.) here
    })
    ->create();

API Middleware

Attach only the middleware that fits your API architecture.

Laravel 10.x (app/Http/Kernel.php)

protected $middlewareGroups = [
    'api' => [
        // ... existing middleware
        \Snowsoft\LaravelPageSpeed\Middleware\ApiSecurityHeaders::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiResponseCache::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiETag::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiResponseCompression::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiPerformanceHeaders::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiCircuitBreaker::class,
        \Snowsoft\LaravelPageSpeed\Middleware\ApiHealthCheck::class,
    ],
];

Laravel 11.x, 12.x and 13.x (bootstrap/app.php)

Inside the same ->withMiddleware closure from the Web section, append the API stack:

$middleware->appendToGroup('api', [
    \Snowsoft\LaravelPageSpeed\Middleware\ApiSecurityHeaders::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiResponseCache::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiETag::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiResponseCompression::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiPerformanceHeaders::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiCircuitBreaker::class,
    \Snowsoft\LaravelPageSpeed\Middleware\ApiHealthCheck::class,
]);

Publish assets and baseline environment variables

composer require snowsoft/laravel-page-speed
php artisan vendor:publish --provider="Snowsoft\\LaravelPageSpeed\\ServiceProvider"

Recommended baseline for cached APIs:

LARAVEL_PAGE_SPEED_ENABLE=true
API_CACHE_ENABLED=true
API_CACHE_DRIVER=redis
API_CACHE_TTL=300
API_CACHE_DYNAMIC_TAGS=true

Measured Impact

Metric Before After (cache hit) Delta
Page Size (Blade) 245 KB 159 KB -35%
First Paint 1.8 s 1.2 s -33%
API Payload 15.2 KB 2.8 KB -82%
Average API Latency 450 ms 2 ms -99.6%
SQL Queries (100-item list) 35 0 -100%
Monthly Bandwidth (estimate) 15 TB 3 TB -80%

Reference scenario: 1M requests/day with a 65% cache hit rate.

Observability and Resilience

  • Performance headers: X-Response-Time, X-Memory-Usage, X-Cache-Status, X-Circuit-Breaker-State ready for ingestion by Datadog, New Relic, or Prometheus scrapers.
  • Configurable circuit breaker: customize failure thresholds, timeout, and scope (route, endpoint, or path) via configuration.
  • Adaptive health check: aggregates database, cache, disk, and queue probes with optional 10-second result caching.
  • Debug-aware skipping: curated skip patterns avoid instrumenting Debugbar, Telescope, Horizon, or custom diagnostic routes.

Documentation Suite

Contributing and Support

  • Review CONTRIBUTING.md before opening pull requests.
  • Run composer test (or docker compose exec app vendor/bin/phpunit) prior to submitting changes.
  • File issues and start discussions via GitHub Issues and Discussions.
  • Distributed under the MIT license.

snowsoft/laravel-page-speed 适用场景与选型建议

snowsoft/laravel-page-speed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「html」 「minify」 「laravel」 「optimize」 「page speed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 snowsoft/laravel-page-speed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 snowsoft/laravel-page-speed 我们能提供哪些服务?
定制开发 / 二次开发

基于 snowsoft/laravel-page-speed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-03