samjuk / m2-module-fetch-priority
Adds ability to set fetch priority attributes, preload/prefetch links for admin content. As well as a public API for extension from 3rd party modules
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-02-25 11:54:30 UTC
README
This module adds options to set the fetch priority & lazy loading attribute on images added via the admin area.
It also provides a simple API to add preload & prefetch link tags to the header from other modules.
Installation
composer config repositories.samjuk-m2-module-fetch-priority vcs git@github.com:SamJUK/m2-module-fetch-priority.git
composer require samjuk/m2-module-fetch-priority:@dev
php bin/magento setup:upgrade && php bin/magento cache:flush
Link Tag Usage
To use this module to add preload/prefetch link tags
Example Preload Usage
class MyClassToAddPreloads { public function __construct( private readonly \SamJUK\FetchPriority\Model\LinkStore $linkStore, private readonly \SamJUK\FetchPriority\Model\LinksPreloadFactory $preloadFactory ) { } public function execute() { // Do Stuff $preload = $this->preloadFactory->create([ 'href' => 'https://app.magento2.test/media/my_custom_entity/image1.jpg', 'mimeType' => \SamJUK\FetchPriority\Enum\FetchPriority\Preload\MimeType::ImageJPEG, 'asType' => \SamJUK\FetchPriority\Enum\FetchPriority\Preload\AsType::Image, 'fetchPriority' => \SamJUK\FetchPriority\Enum\FetchPriority::High ]); $this->linkStore->add($preload); } }
Example Prefetch Usage
class MyClassToAddPrefetches { public function __construct( private readonly \SamJUK\FetchPriority\Model\LinkStore $linkStore, private readonly \SamJUK\FetchPriority\Model\LinksPrefetchFactory $preloadFactory ) { } public function execute() { // Do Stuff $prefetch = $this->preloadFactory->create([ 'href' => 'https://app.magento2.test/media/my_custom_entity/image1.jpg', ]); $this->linkStore->add($prefetch); } }