melbahja/http2-pusher

PHP Http2 服务器推送器

v1.1.0 2020-11-16 22:02 UTC

This package is auto-updated.

Last update: 2024-09-17 06:47:40 UTC


README

PHP Http2 服务器推送器

关于 Http2 服务器推送

HTTP/2 推送允许 web 服务器在浏览器请求资源之前将其发送到浏览器。这在很大程度上是一种性能技术,可以帮助某些网站更快地加载。 - 维基百科

http2 图片由 cloudflare 提供

安装

使用 composer: composer require melbahja/http2-pusher

用法

获取实例

require 'vendore/autoload.php';

use Melbahja\Http2\Pusher;

$pusher = Pusher::getInstance();

示例

// set css file
$pusher->link('/assets/css/style.css');

// set css and image and src
$pusher->link('/asstes/css/main.css')
	->src('/assets/js/scripts.js')
	->img('/assets/img/logo.png')
	-set(Pusher::IMG, '/assets/img/logo2.png');


// set link with options
$pusher->link('https://fonts.gstatic.com', [
	'as' => false,
	'rel' => 'preconnect' 
]);	

// rel by default is preload
// as by default is the link type 


// push header
$pusher->push();

公共方法

Pusher::getInstance(): PusherInterface

Pusher::link(string $link, array $opts = []): PusherInterface

Pusher::src(string $link, array $opts = []): PusherInterface

Pusher::img(string $link, array $opts = []): PusherInterface

Pusher::set(string $type, string $link, array $opts = []): PusherInterface

Pusher::getHeader(string $type = null): string

Pusher::push(string $type = null): void

Pusher::public function toHeader(string $type, array $urls): null|string

许可证

MIT 版权 (c) 2017 Mohamed Elbahja