New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

adexos/magento2-csspreload

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adexos/magento2-csspreload

Magento 2 module that allows loading of stylesheets with the preload attribute

magento2-module
Source
Packagist
Version
1.2.3
Version published
Total downloads
2.9K
Maintainers
2
Created
Source

Magento 2 CSS Preload

Simple module that allows for asynchronous CSS loading in Magento 2

Installation

  • Go to your Magento root directory
  • Run composer require meanbee/magento2-csspreload

Development

Setting up a development environment

A Docker development environment is included with the project:

docker-compose run --rm cli magento-extension-installer Meanbee_CSSPreload
docker-compose up -d

Usage

To add assets to the block, provide the assets argument:

<referenceBlock name="head.csspreload">
    <arguments>
        <argument name="assets" xsi:type="array">
            <item name="unique_name" xsi:type="array">
                <item name="path" xsi:type="string">css/filename.css</item>
                <item name="attributes" xsi:type="array">
                    <item name="name" xsi:type="string">attribute</item>
                    <item name="value" xsi:type="string">value</item>
                </item>
            </item>
        </argument>
    </arguments>
</referenceBlock>

To modify the template of the generated <link /> tags, provide a link_template argument, e.g.:

<referenceBlock name="head.csspreload">
    <arguments>
        <argument name="link_template" xsi:type="string"><![CDATA[<link rel="preload" as="style" href=":path:" onload="this.rel='stylesheet'" :attributes: />]]></argument>
    </arguments>
</referenceBlock>

There are two variables that will be substituted: :path:, which will be replaced by the asset path, and :attributes: that will contain your attributes of your assets as HTML attributes.

FAQs

Package last updated on 22 Mar 2019

Related posts