dan0sz / resource-hints-magento2

dan0sz/resource-hints-magento2

Add `<link rel='preconnect'>`, `<link rel='dns-prefetch'>`, `<link rel='prefetch'>`, or `<link rel='preload'>` resource hints to Magento 2's head.

magento2-module Compatibility: Not yet tested Code Quality: Warning Tests: N/A Security: Pass CC-BY-4.0

Are you the maintainer of dan0sz?

Packagento pulls dan0sz's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

THIS EXTENSION IS NO LONGER ACTIVELY MAINTAINED

If it doesn't work on your Magento 2 instance, please fork this repo and fix it -- and feel free to submit a PR to add your changes to this repo.

Update January 31st, 2022: I've removed the Magento version requirements from composer.json so that you can try it on any instance. I'm not guaranteeing it'll work.

Resource Hints for Magento 2

Overview

Add <link rel='preconnect'>, <link rel='dns-prefetch'>, <link rel='prefetch'>, or <link rel='preload'> resource hints to Magento 2's head.

Features

  • Tweak your Magento 2 store's performance by adding custom preconnect, dns-prefetch, prefetch, and preload headers.
  • Enable/disable crossorigin attribute.
  • Easily configurable at default, website and store view level (incl. sort order).

Installation

Using Composer

Installation using Composer is easy and recommended. From a terminal, just run:

composer require dan0sz/resource-hints-magento2

Manually

If you can't or dont want to use Composer, you can download the master-branch of this repository and copy the contents to app/code/Dan0sz/ResourceHints.

After installation

Developer Mode

  • Run bin/magento setup:upgrade
  • Done!

Production Mode

  • Run bin/magento setup:upgrade
  • Run bin/magento setup:di:compile
  • Run bin/magento setup:static-content:deploy [locales e.g. en_US nl_NL]
  • Done!

Configuration

After installation a new tab is added to Stores > Configuration > General > Web called Resource Hints.

How does it work?

While most settings of this extension speak for themselves. The Resource column contains a few nifty tricks (thanks to @chedaroo), which will come in handy when e.g. Static content signing is enabled.

Values in the Resource column are assumed to be relative (local) assets. When a relative path is entered and Static Content Signing is enabled, e.g.

(In these examples it is assumed that the default theme, Magento Luma is used.)

  • YourName_ModuleName::path/to/file.ext will resolve to https://yourdomain.tld/static/<<deployment_version>>/frontend/Magento/luma/en_US/YourName_ModuleName/path/to/file.ext, and
  • path/to/file.ext will resolve to https://yourdomain.tld/static/<<deployment_version>>/frontend/Magento/luma/en_US/path/to/file.ext.

When Static Content Signing is disabled, the above mentioned values will resolve to:

  • https://yourdomain.tld/static/frontend/Magento/luma/en_US/YourName_ModuleName/path/to/file.ext, and
  • https://yourdomain.tld/static/frontend/Magento/luma/en_US/path/to/file.ext respectively.

When absolute URLs (prefixed by a protocol, i.e. http://, https:// or //) are entered in the Resource column, no prior resolving will take place. E.g.

  • http://yourdomain.tld/path/to/file.ext,
  • https://yourdomain.tld/path/to/file.ext, and
  • //SomeVolume/path/to/file.ext.

The examples above will all resolve to the same exact URL.

No changelog yet

The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.

Versions
Version Stability QA Status Compatibility Released
v1.2.1 stable Not tested Not yet tested Details 2023-01-31 14:04:36
1.2.0 stable Pass Not yet tested Details 2021-01-20 13:20:16
1.1.0 stable Not tested Not yet tested Details 2020-11-18 17:01:51
1.0.1 stable Not tested Not yet tested Details 2020-01-08 13:30:01
1.0.0 stable Not tested Not yet tested Details 2019-08-27 18:27:54

Requires 4

Package Constraint
ext-json *
ext-openssl *
magento/framework 101.*|102.*|103.*
php 7.*

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.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 not tested not tested
2.4.8 not tested not tested
2.4.9 not tested not tested

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.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 13 13 warnings (ruleset: Magento2) — 8 auto-fixable with phpcbf
PHPMD Warning 1 1 rule violation (UnusedFormalParameter:1)
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
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

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

Unit tests results by Magento and PHP version
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

Integration tests results by Magento and PHP version
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.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
CC-BY-4.0
Homepage
https://daan.dev
Authors
Make it pay

Turn 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.