justbetter/laravel-http3earlyhints
Composer 安装命令:
composer require justbetter/laravel-http3earlyhints
包简介
A HTTP3 Early Hints Middleware for Laravel
README 文档
README
Early Hints is a HTTP/3 concept which allows the server to send preconnect and preload headers while it's still preparing a response. This allows the broser to start loading these resources before the server has finished building and sending a response See.
This package aims to provide the easiest experience for adding Early Hints to your responses.
Simply route your requests through the AddHttp3EarlyHints middleware and it will automatically create and attach the Link headers necessary to implement Early Hints for your CSS, JS and Image assets.
Installation
You can install the package via composer:
$ composer require justbetter/laravel-http3earlyhints
Next you must add the \JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints-middleware to the kernel. Adding it to the web group is recommeneded as API's do not have assets to push.
Laravel <11
// app/Http/Kernel.php ... protected $middlewareGroups = [ 'web' => [ ... \JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class, ... ], ... ];
Laravel >=11
// bootstrap/app.php ... ->withMiddleware(function (Middleware $middleware) { ... $middleware->appendToGroup('web', [ \JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class, ]); // Or // $middleware->append(\JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class); ... }) ...
Publish config
php artisan vendor:publish --provider="JustBetter\Http3EarlyHints\ServiceProvider"
Note: send_103 defaults to false, this is because it isn't actually supported widely yet. Currently only FrankenPHP supports Early Hints natively.
default behaviour is adding the link headers to the 200 response which e.g. Cloudflare turns into early hints.
Usage
When you route a request through the AddHttp3EarlyHints middleware, the response is scanned for any link, script or img tags that could benefit from being loaded using Early Hints.
These assets will be added to the Link header before sending the response to the client. Easy!
Note: To push an image asset, it must have one of the following extensions: bmp, gif, jpg, jpeg, png, svg, tiff or webp and not have loading="lazy"
Advanced usage
If the automatic detection isn't enough for you, you can listen for the GenerateEarlyHints event, and manually add/remove/change new links.
Detailed default behaviour
The information on usage is simplified, there are many checks done to make sure we don't preload the wrong things.
Early hints only support rel=preconnect and rel=preload source
We automatically transform any rel that is not preconnect or preload into preload, so your <link rel="modulepreload" href="app.js"> will get preloaded with early hints. And get more detailed information once your server starts sending it's response.
Link
Any link elements which do not have rel=
- icon
- canonical
- manifest
- alternative
Script
Script tags will automatically get preloaded if it does not have an async or defer attribute attached to it.
Img
Img tags will automatically get preloaded when it does not have loading="lazy" and it does not exist within a picture tag.
If it is within a picture tag we may be dealing with mutliple srcsets or types, and thus cannot determine which file the browser will need.
So we will not preload these images.
Object
If your html object tag contains data="" it will preload it.
Nonce
While the early hints module does support sending nonce across as well, we recommend against it. And use integrity instead.
Without hardcoding the nonce Vite::useCspNonce($nonce); sending this in early hints will be useless as each request will send early hints with a stale nonce.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
justbetter/laravel-http3earlyhints 适用场景与选型建议
justbetter/laravel-http3earlyhints 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76.56k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2024 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「serverpush」 「http3」 「laravel-http3earlyhints」 「early hints」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 justbetter/laravel-http3earlyhints 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 justbetter/laravel-http3earlyhints 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 justbetter/laravel-http3earlyhints 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A HTTP2 Server Push Middleware for Laravel 5
Use Cloudflare's no-CAPTCHA with HTTP/3 in your Laravel application.
Supercharge your Yii2 applications with FrankenPHP blazing-fast HTTP server.
A HTTP2 Server Push Middleware for Laravel 5
A HTTP2 Server Push Middleware for Laravel 6 & 7
Alfabank REST API integration
统计信息
- 总下载量: 76.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 35
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-23