xanweb/c5-web-link

管理HTML头部链接以提升页面加载性能

v2.0.2 2022-12-05 15:20 UTC

This package is auto-updated.

Last update: 2024-09-05 19:23:31 UTC


README

Latest Version on Packagist Software License

管理HTML头部链接以提升页面加载性能

安装

将库包含到你的 composer.json 中

composer require xanweb/c5-web-link

将服务提供者和中间件添加到 application/config/app.php

return [
    'providers' => [
        'xw_web_link' => '\Xanweb\C5\WebLink\ServiceProvider'
    ]
];

确保你正在加载供应商自动加载 application/bootstrap/autoload.php

<?php

defined('C5_EXECUTE') or die('Access Denied.');

/*
 * ----------------------------------------------------------------------------
 * Load all composer autoload items.
 * ----------------------------------------------------------------------------
 */

// If the checker class is already provided, likely we have been included in a separate composer project
if (!class_exists(\DoctrineXml\Checker::class)) {
    // Otherwise, lets try to load composer ourselves
    if (!@include(DIR_BASE_CORE . '/' . DIRNAME_VENDOR . '/autoload.php')) {
        echo 'Third party libraries not installed. Make sure that composer has required libraries in the concrete/ directory.';
        die(1);
    }
}

if (file_exists(DIR_BASE . '/' . DIRNAME_VENDOR . '/autoload.php')) {
    include_once (DIR_BASE . '/' . DIRNAME_VENDOR . '/autoload.php');
}

使用

    use \Fig\Link\Link;
    use \Fig\Link\Relations;

    // Example with Font Preload
    $link = (new Link(Relations::REL_PRELOAD, '/path/to/font.woff2'))
                ->withAttribute('as', 'font')
                ->withAttribute('type', 'font/woff2')
                ->withAttribute('crossorigin', 'anonymous');

    app('web/link')->queueLink($link);