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

`composer require dan0sz/resource-hints-magento2`

Canonical URL: https://packagento.com/dan0sz/resource-hints-magento2

## At a glance

- **Vendor**: dan0sz (https://packagento.com/dan0sz.md)
- **Latest version**: v1.2.1 — released 2023-01-31
- **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/dan0sz/resource-hints-magento2 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 dan0sz/resource-hints-magento2:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

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

## README

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.

## Recent Versions

| Version | Released |
|---|---|
| v1.2.1 | 2023-01-31 |
| 1.2.0 | 2021-01-20 |
| 1.1.0 | 2020-11-18 |
| 1.0.1 | 2020-01-08 |
| 1.0.0 | 2019-08-27 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| ext-json | * |
| ext-openssl | * |
| magento/framework | * |

## 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=["dan0sz/resource-hints-magento2"],
  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

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

