slexx/laravel-webp

检测 Laravel 框架中的 webp 支持情况

dev-master 2018-12-29 10:24 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:41 UTC


README

安装

$ composer require slexx/laravel-webp

在 Laravel 5.5 中,服务提供器将自动注册。在框架的旧版本中,只需在 config/app.php 文件中添加服务提供器

'providers' => [
    // ...
    Slexx\LaravelWebp\LaravelWebpServiceProvider::class,
];

@webpJS 指令添加到 <head> 标签

<head>
    @webpJS
    <!-- ... -->
</head>

用法

Blade 中的用法

@webp
    <img src="/image.webp"/>
@else
    <img src="/image.png"/>
@endwebp

或者在 js, php 中

if (supportsWebp()) {
    // Does support!
} else {
    // Does not support!
}

或者在 css 中

html.webp {
    /* Does support! */
}

html.no-webp {
    /* Does not support! */
}