spatie/lighthouse-php

使用PHP运行Google Lighthouse

资助包维护!
spatie

1.2.2 2024-05-06 09:03 UTC

This package is auto-updated.

Last update: 2024-09-08 11:36:18 UTC


README

Latest Version on Packagist Tests Total Downloads

Google Lighthouse 是一个开源的、自动化的工具,用于提高网页质量。它提供了性能、可访问性、渐进式Web应用、SEO等方面的审核。

此包使得使用PHP运行Lighthouse变得容易。以下是如何获取Lighthouse提供的五个审核类别的分数的示例。

use Spatie\Lighthouse\Lighthouse;

// returns an instance of Spatie\Lighthouse\LighthouseResult
$result = Lighthouse::url('https://example.com')->run();

$result->scores(); // returns an array like this one:
/*
 * [
 *    'performance' => 98,
 *    'accessibility' => 83,
 *    'best-practices' => 90,
 *    'seo' => 92,
 *    'pwa' => 43,  
 * ]
 */

配置各种选项非常容易

use Spatie\Lighthouse\Lighthouse;
use Spatie\Lighthouse\Enums\Category;

Lighthouse::url('https://example.com')
    ->userAgent('My user agent')
    ->headers(['MyExtraHeader' => 'HeaderValue'])
    ->categories(Category::Performance, Category::Accessibility)
    ->throttleCpu()
    ->run();

以下是如何获取审核结果的示例

$result->audit('first-contentful-paint') // returns this array

/*
 * [
 *     'id' => 'first-contentful-paint'
 *     'title' => 'First Contentful Paint'
 *     'score' => 0.98
 *     'scoreDisplayMode' => 'numeric'
 *     'numericValue' => 1262.95
 *     'numericUnit' => 'millisecond'
 *     'displayValue' => '1.3 s'
 * ]
 */

您还可以将完整的HTML报告写入磁盘

$result->saveHtml($pathToReport)

支持我们

我们投入了大量资源来创建一流的开放源代码包。您可以通过购买我们的付费产品之一来支持我们。

我们非常感谢您从家乡寄给我们明信片,并提到您正在使用我们的哪个包。您可以在我们的联系页面上找到我们的地址。我们将在我们的虚拟明信片墙上发布所有收到的明信片。

文档

所有文档都可以在我们的文档网站上找到

测试

composer test

更新日志

请参阅更新日志以获取有关最近更改的更多信息。

贡献

请参阅贡献以获取详细信息。

安全漏洞

请查看我们的安全策略,了解如何报告安全漏洞。

鸣谢

此包包含从Laravel的Arr中复制的代码。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件