ldavidsp / laravel-page-speed
Laravel Page Speed
v9.0.0
2022-02-22 00:41 UTC
Requires
- php: ^5.6 || ^7.0 || ^8.0 || ^9.0
- illuminate/support: 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0 || ^8.0 || ^9.0
Requires (Dev)
- mockery/mockery: >=0.9.4
- orchestra/testbench: ^3.2
- phpunit/phpunit: ^5.7 || ^6.0 || ^7.0 || ^8.0
- squizlabs/php_codesniffer: ^2.3
README
Laravel Page Speed
这是一个简单的包,可以根据需求压缩HTML输出,从而实现35%以上的优化。
安装
您可以通过composer安装此包
$ composer require renatomarinho/laravel-page-speed
Laravel 5.5及以上
Laravel 5.5及以上使用包自动发现功能,因此不需要您手动添加ServiceProvider。
Laravel 5.4或5.3
将ServiceProvider添加到config/app.php中的providers数组
RenatoMarinho\LaravelPageSpeed\ServiceProvider::class
这是发布配置文件所必需的
发布配置文件
php artisan vendor:publish --provider="RenatoMarinho\LaravelPageSpeed\ServiceProvider"
请务必注册中间件
接下来,必须在kernel中注册\RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class
和其他中间件
//app/Http/Kernel.php protected $middleware = [ ... \RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class, \RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class, \RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class, \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class, \RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class, \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class, \RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class, ]
之前
之后
路线图:过滤器
配置
安装包后,您可能需要配置一些选项。
禁用服务
您可能希望设置本地环境以获取可读的输出。
//config/laravel-page-speed.php //Set this field to false to disable the laravel page speed service. 'enable' => env('LARAVEL_PAGE_SPEED_ENABLE', true),
跳过路由
您可能希望配置包以跳过一些路由。
//config/laravel-page-speed.php //You can use * as wildcard. 'skip' => [ '*.pdf', //Ignore all routes with final .pdf '*/downloads/*',//Ignore all routes that contain 'downloads' 'assets/*', // Ignore all routes with the 'assets' prefix ];
默认情况下,此字段已配置了一些选项,因此请根据您的需求进行配置...
注意:此包会自动跳过'二进制'和'流式'响应。请参阅 文件下载。
警告
\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class被认为是中等风险。如果它使用错误的基准URL,则可能会引起问题。例如,如果您提供将被直接粘贴到其他HTML页面中的HTML,则可能会发生这种情况。如果URL在第一页上被裁剪,它们将被插入的页面视为不正确。在这种情况下,只需禁用中间件即可。
测试
$ composer test
贡献
请参阅CONTRIBUTING以获取详细信息。
鸣谢
灵感来源
Mod Page Speed (https://www.modpagespeed.com/)
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。