# 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

`composer require samjuk/m2-module-fetch-priority`

Canonical URL: https://packagento.com/samjuk/m2-module-fetch-priority

## At a glance

- **Vendor**: samjuk (https://packagento.com/samjuk.md)
- **Latest version**: v1.0.0 — released 2026-07-15
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/samjuk/m2-module-fetch-priority and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require samjuk/m2-module-fetch-priority:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

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

## README

[![Supported Magento Versions](https://img.shields.io/badge/magento-2.4.6%E2%80%932.4.8-orange.svg?logo=magento)](https://github.com/SamJUK/m2-module-fetch-priority/actions/workflows/ci.yml)
[![CI Workflow Status](https://github.com/samjuk/m2-module-fetch-priority/actions/workflows/ci.yml/badge.svg)](https://github.com/SamJUK/m2-module-fetch-priority/actions/workflows/ci.yml)
[![GitHub Release](https://img.shields.io/github/v/release/SamJUK/m2-module-fetch-priority?label=Latest%20Release&logo=github)](https://github.com/SamJUK/m2-module-fetch-priority/releases)

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`/`Prefetch` factories) 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
```sh
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
```php
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
```php
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](CONTRIBUTING.md).

### Security

See [SECURITY.md](SECURITY.md) for reporting vulnerabilities.

### License

[MIT](LICENSE)

## Recent Versions

| Version | Released |
|---|---|
| v1.0.0 | 2026-07-15 |
| v0.0.5 | 2026-01-12 |
| v0.0.4 | 2025-04-24 |
| v0.0.3 | 2025-03-28 |
| v0.0.2 | 2025-03-28 |
| v0.0.1 | 2025-02-25 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| php | ^8.1 |

### Require (dev)

| Package | Constraint |
|---|---|
| phpstan/phpstan | ^1.12 |
| phpunit/phpunit | ^10.5 |

## Quality

Latest release (v1.0.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — 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 |  |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 2 | 2 | – | – |
| 2.4.8 | – | 2 | 2 | – |
| 2.4.9 | – | – | 2 | 2 |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit 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 |

#### 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

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["samjuk/m2-module-fetch-priority"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

samjuk is a Magento 2 vendor on Packagento. See https://packagento.com/samjuk.md for their full catalogue.

