m2-boilerplate/module-critical-css 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

m2-boilerplate/module-critical-css

Composer 安装命令:

composer require m2-boilerplate/module-critical-css

包简介

Magento 2 module to automatically generate critical css with the addyosmani/critical npm package

README 文档

README

Magento 2 module to automatically generate critical css with critical

Features:

  • generate critical css with a simple command
  • Fallback critical css for "empty" pages
  • Add urls by creating a custom provider

Installation

Install the critical binary. Install instructions can be found on the critical website. Only versions >=2.0.3 are supported.

Add this extension to your Magento installation with Composer:

composer require m2-boilerplate/module-critical-css

Usage

Configuration

The critical css feature needs to be enabled (available in 2.3.4+):

bin/magento config:set dev/css/use_css_critical_path 1

Features can be customised in Stores > Configuration > Developer > CSS.

Generate critical css

Run the following command

bin/magento m2bp:critical-css:generate

Afterwards you should find the the generated css in var/critical-css. The css will now be integrated automatically on your website.

Add additional URLs via a custom provider

The following example adds the magento contact page via a custom provider:

<?php

namespace Vendor\Module\Provider;

use Magento\Framework\App\Request\Http;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\Store\Api\Data\StoreInterface;
use M2Boilerplate\CriticalCss\Provider\ProviderInterface;
  
class CustomProvider implements ProviderInterface
{
    const NAME = 'custom_example';

    /**
     * @var UrlInterface
     */
    protected $url;

    public function __construct(UrlInterface $url)
    {
        $this->url = $url;
    }


    public function getUrls(StoreInterface $store): array
    {
        return [
            'contact_index_index' => $this->url->getUrl('contact'),
        ];
    }

    public function getName(): string
    {
        return self::NAME;
    }

    public function isAvailable(): bool
    {
        return true;
    }

    public function getPriority(): int
    {
        return 1200;
    }

    public function getCssIdentifierForRequest(RequestInterface $request, LayoutInterface $layout): ?string
    {
        if ($request->getModuleName() !== 'contact' || !$request instanceof Http) {
            return null;
        }
        
        if ($request->getFullActionName('_') === 'contact_index_index') {
            return 'contact_index_index';
        }

        return null;
    }
}

Add the new provider via DI:

in your module´s etc/di.xml add the following:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="M2Boilerplate\CriticalCss\Provider\Container">
        <arguments>
            <argument name="providers" xsi:type="array">
                <item name="custom_example" xsi:type="object">Vendor\Module\Provider\CustomProvider</item>
            </argument>
        </arguments>
    </type>
</config>

License

See the LICENSE file for license info (it's the MIT license).

m2-boilerplate/module-critical-css 适用场景与选型建议

m2-boilerplate/module-critical-css 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83.73k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2020 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 m2-boilerplate/module-critical-css 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 m2-boilerplate/module-critical-css 我们能提供哪些服务?
定制开发 / 二次开发

基于 m2-boilerplate/module-critical-css 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 83.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 37
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 36
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-05