mako/pusher

该包已被弃用,不再维护。未建议替代包。

Mako 框架的资产预加载

4.0.0 2021-11-30 12:35 UTC

README

Build Status

Pusher 允许您轻松地在应用程序中实现 预加载预取预渲染dns预取预连接

要求

Mako 8.0 或更高版本。

使用方法

如果您正在使用 PusherMiddleware,则可以使用 Request::getAttribute() 方法访问 Pusher 实例。

$pusher = $this->request->getAttribute('mako.pusher');

您可以让客户端预加载您的资源。

$pusher->push('/assets/css/style.css', ['preload']);

// You can also use the "preload" convenience method

$pusher->preload('/assets/css/style.css');

预加载需要一个支持推送的 HTTP2 服务器(例如 Apache 2.4.24+)。

您可以让浏览器预取您认为用户接下来可能需要的资源。

$pusher->push('https://example.org/image.jpg', ['prefetch', 'as' => 'image']);

// You can also use the "prefetch" convenience method

$pusher->prefetch('https://example.org/image.jpg', ['as' => 'image']);

您可以让浏览器预取并渲染您认为用户接下来可能访问的资源。

$pusher->push('https://example.org/next', ['prerender']);

// You can also use the "prerender" convenience method

$pusher->prerender('https://example.org/next');

您可以解析客户端在获取资源时需要连接到的域名的 DNS 查找。

$pusher->push('https://fonts.gstatic.com', ['dns-prefetch']);

// You can also use the "dnsPrefetch" convenience method

$pusher->dnsPrefetch('https://fonts.gstatic.com');

您可以预先连接到客户端在获取资源时需要连接到的域名。这将解析 DNS 查找,但也包括 TCP 握手和可选的 TLS 协商。

$pusher->push('https://fonts.gstatic.com', ['preconnect', 'crossorigin' => true]);

// You can also use the "preconnect" convenience method

$pusher->preconnect('https://fonts.gstatic.com', ['crossorigin' => true]);

更多详细信息