# elgentos/module-lightspeed

> Magento 2 Lightspeed optimizations

`composer require elgentos/module-lightspeed`

Canonical URL: https://packagento.com/elgentos/module-lightspeed

## At a glance

- **Vendor**: elgentos (https://packagento.com/elgentos.md)
- **Latest version**: 1.0.3 — released 2025-05-09
- **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/elgentos/module-lightspeed 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 elgentos/module-lightspeed:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Magento 2 Lightspeed optimizations

## README

Process your Google Lighthouse feedback using sane defaults. This module defines several sections where you can define
common feedback from Google Lighthouse.

### Installation

Run this in your Magento 2 project root;

```bash
composer require elgentos/module-lightspeed
php bin/magento module:enable Elgentos_Lightspeed
php bin/magento setup:upgrade
```

### Features

#### Javascript handling
Move all `script` tags before body end. This is the default after installing this module, no exceptions.

#### Connection optimization (layout.xml)
Allow modern browsers to use DNS prefetching and preconnecting.

DNS prefetching only does a DNS lookup, preconnecting already connects to the remote server and does SSL handshake.
Preconnecting is limited to a few connections which is defined in your browser, we have fallback to DNS-prefetching,
but think before you add everything to `preconnect`.

#### Fonts (layout.xml)
Load external fonts to the head section.

#### Styles (layout.xml)
Inline CSS in the head or before body end for critical CSS.

#### External CSS (layout.xml)
We have several options for optimizing external CSS;
* Directly in the head;
* Before body end;
* Defer till all other stuff is done.

#### Javascript (layout.xml)
Javascript via XML before body end via layout XML.

### Usage

Preferred usage to keep everything together is to add a handle to `layout/default.xml`.
You can also add controller specific rules, add them in the controller specific handles, for instance `layout/catalog_category_default.xml`

You can also add specific rules and bind them to your module, instead to the theme.

`app/design/frontend/your/theme/Magento_Theme/layout/default.xml`
```xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="default_lightspeed" />

    <!-- .... snap ... -->

</page>
``` 

After that all default lighthouse feedback can go into `layout/default_lightspeed.xml`

`app/design/frontend/your/theme/Magento_Theme/layout/default_lightspeed.xml`
```xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <body>
        <referenceBlock name="lightspeed.head.dns-prefetch">
            <!-- Use addItems to add multiple values without writing to much code -->
            <action method="addItems">
                <argument name="items" xsi:type="array">
                    <item name="google" xsi:type="string">www.google.com</item>
                    <item name="google-static" xsi:type="string">www.gstatic.com</item>
                    <item name="google-adservices" xsi:type="string">www.googleadservices.com</item>
                    <!-- .... etc ... -->
                </argument>
            </action>
        </referenceBlock>
    
        <referenceBlock name="lightspeed.head.preconnect">
            <action method="addItems">
                <argument name="items" xsi:type="array">
                    <item name="google-apis" xsi:type="string">fonts.googleapis.com</item>
                    <item name="google-fonts" xsi:type="string">fonts.gstatic.com</item>
    
                    <!-- .... etc ... -->
                    
                    <item name="google-gtm" xsi:type="string">www.googletagmanager.com</item>
                </argument>
            </action>
        </referenceBlock>

        <referenceBlock name="lightspeed.head.fonts">
            <!-- Use addItem if you just need to add one line -->
            <action method="addItem">
                <argument name="value" xsi:type="string">https://fonts.googleapis.com/css?family=Font&amp;amp;display=swap</argument>
            </action>
            <!-- .... etc ... -->
        </referenceBlock>

        <!-- Choose if you want your css to go in the head, or in the footer -->
        <referenceBlock name="lightspeed.head.inline-styles">
            <action method="addItem">
                <argument name="value" xsi:type="string"><![CDATA[*{color: red !important;}]]></argument>
            </action>
        </referenceBlock>
        <referenceBlock name="lightspeed.body.inline-styles">
            <action method="addItem">
                <argument name="value" xsi:type="string"><![CDATA[*{color: red !important;}]]></argument>
            </action>
        </referenceBlock>

        <referenceBlock name="lightspeed.body.defer-styles">
            <action method="addItem">
                <!-- Use a custom helper if you need to add some logic outside of layout.xml, needs to return a string -->
                <argument name="value" xsi:type="helper" helper="Magento\Helper\Data::getStyleSheet" />
            </action>
        </referenceBlock>
        <!-- Use defer styles which waits till all js/css painting is done -->
        <referenceBlock name="lightspeed.body.no-defer-styles">
            <action method="addItem">
                <argument name="value" xsi:type="helper" helper="Magento\Helper\Data::getStyleSheet" />
            </action>
        </referenceBlock>

    </body>
</page>
``` 

### Block quick references

#### References HEAD

* `lightspeed.head.dns-prefetch`
* `lightspeed.head.preconnect`
* `lightspeed.head.fonts`
* `lightspeed.head.inline-styles`

#### References (before body end)

* `lightspeed.body.defer-styles`
* `lightspeed.body.no-defer-styles`
* `lightspeed.body.inline-styles`
* `lightspeed.body.footer-js`

### Block code reference

You can also use `\Elgentos\Lightspeed\Block\ItemsWithPattern` to add your own references.

Public:
* `addItem(string $value): void`
* `addItems(array $values): void`
* `getItems(): array`
* `hasItems(): bool`
* `removeItem(string $value): void`
* `setPattern(string $pattern): void`
* `render(): string`

#### Custom block definition

_(README truncated for .md surface. Full README on https://packagento.com/elgentos/module-lightspeed.)_

## Recent Versions

| Version | Released |
|---|---|
| 1.0.3 | 2025-05-09 |
| 1.0.2 | 2020-02-06 |
| 1.0.1 | 2020-02-06 |
| 1.0.0 | 2020-02-06 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | * |
| php | >=7.2 |

## Quality

Latest release (1.0.3) 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 | Fail | 10 | 3 errors, 7 warnings (ruleset: Magento2) — 4 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 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 | 3 | 3 | – | – |
| 2.4.8 | – | 3 | 3 | – |
| 2.4.9 | – | – | 3 | 3 |


### 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=["elgentos/module-lightspeed"],
  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

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

