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
SamJUK_FetchPriority
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.
Features
- Automatic
<link rel="preload">for the product page main image, so the browser fetches it before it discovers the<img>tag. - Automatic preload for the first 4 product images in a category grid (above-the-fold products).
fetch-priority/loading/ preload controls for PageBuilder image content type (desktop & mobile images).- Public API (
LinkStore+Preload/Prefetchfactories) to add your own preload/prefetch links from any module. - Every feature above can be toggled independently, or disabled globally, via admin config.
Requirements
- Magento 2.4.6 - 2.4.8 (see CI matrix badge above)
- PHP 8.1+
Installation
composer require samjuk/m2-module-fetch-priority
php bin/magento setup:upgrade && php bin/magento cache:flush
Configuration
Settings are available at Stores > Configuration > SamJUK > Fetch Priority.
| Path | Field | Default | Description |
|---|---|---|---|
samjuk_fetch_priority/general/enabled |
Enable | Yes | Master switch, disables all preloads when off |
samjuk_fetch_priority/preloads/product_main |
Product Main Image | Yes | Preload the main image on product view pages |
samjuk_fetch_priority/preloads/category_grid |
First 4 Category Products | Yes | Preload the first 4 product images on category pages |
samjuk_fetch_priority/preloads/pagebuilder_content |
PageBuilder Content | Yes | Enable fetch-priority/loading/preload attributes on PageBuilder images |
Scope: default / website / store view.
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\Links\PreloadFactory $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\Preload\MimeType::ImageJPEG,
'asType' => \SamJUK\FetchPriority\Enum\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\Links\PrefetchFactory $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);
}
}
Contributing
Bug reports and PRs welcome — see CONTRIBUTING.md.
Security
See SECURITY.md for reporting vulnerabilities.
License
No changelog yet
The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| v1.0.0 | stable | Fail | Magento 2.4.7-2.4.9 Details | 2026-07-15 23:15:35 |
| v0.0.5 | stable | Not tested | Not yet tested Details | 2026-01-12 11:09:21 |
| v0.0.4 | stable | Not tested | Not yet tested Details | 2025-04-24 15:42:40 |
| v0.0.3 | stable | Not tested | Not yet tested Details | 2025-03-28 21:32:31 |
| v0.0.2 | stable | Not tested | Not yet tested Details | 2025-03-28 00:53:22 |
| v0.0.1 | stable | Not tested | Not yet tested Details | 2025-02-25 11:53:09 |
Requires 1
| Package | Constraint |
|---|---|
| php | ^8.1 |
Requires-dev 2
| Package | Constraint |
|---|---|
| phpstan/phpstan | ^1.12 |
| phpunit/phpunit | ^10.5 |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Warning | 39 | 39 warnings (ruleset: Magento2), 8 auto-fixable with phpcbf |
| PHPMD | Warning | 33 | 33 rule violations (UnusedPrivateField:33) |
| Cpd | Warning | 2 | 2 duplicated chunks spanning 35 total lines (min-lines=5, min-tokens=70) |
| Composer validate | Pass | 0 |
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from samjuk
View vendorTurn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.