PHPackages                             hryvinskyi/magento2-page-speed - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hryvinskyi/magento2-page-speed

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

hryvinskyi/magento2-page-speed
==============================

N/A

1.0.7(1mo ago)51.9k22MITPHP

Since Jun 14Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/hryvinskyi/magento2-page-speed)[ Packagist](https://packagist.org/packages/hryvinskyi/magento2-page-speed)[ RSS](/packages/hryvinskyi-magento2-page-speed/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (9)Versions (9)Used By (2)

Magento 2 Page Speed
====================

[](#magento-2-page-speed)

[![Latest Stable Version](https://camo.githubusercontent.com/8580b3b45c77c52d000a596a09c84b558a37bd415f6dfef17d2fe85df4673a6c/68747470733a2f2f706f7365722e707567782e6f72672f68727976696e736b79692f6d6167656e746f322d706167652d73706565642f762f737461626c65)](https://packagist.org/packages/hryvinskyi/magento2-page-speed)[![Total Downloads](https://camo.githubusercontent.com/adf6f315d168de63b2688d7ca74ae86afe1902ef954bc09309130b289e93a8c8/68747470733a2f2f706f7365722e707567782e6f72672f68727976696e736b79692f6d6167656e746f322d706167652d73706565642f646f776e6c6f616473)](https://packagist.org/packages/hryvinskyi/magento2-page-speed)[![PayPal donate button](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=volodymyr%40hryvinskyi%2ecom&lc=UA&item_name=Magento%202%20Page%20Speed&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted "Donate once-off to this project using Paypal")[![Latest Unstable Version](https://camo.githubusercontent.com/c73b3be5ddd6793d633dac025e5f47c070f664ff17f671b7fef59b3ad2a07f64/68747470733a2f2f706f7365722e707567782e6f72672f68727976696e736b79692f6d6167656e746f322d706167652d73706565642f762f756e737461626c65)](https://packagist.org/packages/hryvinskyi/magento2-page-speed)[![License](https://camo.githubusercontent.com/e520b56999674f567b54fbc9146d91f5b2a62dba60d3b63a10c618d2186cdf12/68747470733a2f2f706f7365722e707567782e6f72672f68727976696e736b79692f6d6167656e746f322d706167652d73706565642f6c6963656e7365)](https://packagist.org/packages/hryvinskyi/magento2-page-speed)

Description
-----------

[](#description)

Core implementation of Page Speed utilities and helpers. Provides concrete implementations of the PageSpeedApi interfaces with intelligent file merging, caching, and HTML manipulation capabilities.

Features
--------

[](#features)

### Intelligent File Merging

[](#intelligent-file-merging)

- **Changelog-Based Merging** - Only merges files when source files are newer than target
- **AbstractMerger** - Base class for implementing file merge operations
- **Extension Filtering** - Filter files by extension during merge
- **Before-Merge Callbacks** - Transform content before merging

### URL &amp; File Management

[](#url--file-management)

- **GetLocalPathFromUrl** - Converts absolute URLs to local filesystem paths
- **GetFileContentByUrl** - Fetches file content from URLs
- **IsInternalUrl** - Validates if URLs are internal to the domain
- **Path Normalization** - Handles various URL formats and edge cases

### HTML Parsing &amp; Manipulation

[](#html-parsing--manipulation)

- **Finder\\Js** - Find JavaScript resources in HTML
- **Finder\\Css** - Find CSS resources in HTML
- **Finder\\HtmlComment** - Find HTML comments
- **Html\\ReplaceIntoHtml** - Replace content within HTML
- **Html\\InsertStringBeforeBodyEnd** - Insert before `` tag
- **Html\\InsertStringBeforeHeadEnd** - Insert before `` tag
- **Html\\GetContent** - Extract content from HTML

### Cache Management

[](#cache-management)

- **Cache** - Implementation for storing optimization artifacts
- **Size Limits** - Configurable cache folder size limits
- **Efficient Storage** - Only stores what's necessary

Installation
------------

[](#installation)

```
composer require hryvinskyi/magento2-page-speed
bin/magento module:enable Hryvinskyi_PageSpeed
bin/magento setup:upgrade
bin/magento cache:flush
```

Technical Details
-----------------

[](#technical-details)

### AbstractMerger Class

[](#abstractmerger-class)

Base class for all file merging operations with intelligent changelog detection:

```
abstract class AbstractMerger
{
    /**
     * Merge files only if source files are newer than target
     *
     * @param array $files Files to merge
     * @param string $targetPath Output file path
     * @param callable|null $beforeMergeCallback Optional content transformation
     * @return bool Success status
     */
    public function merge(array $files, string $targetPath, ?callable $beforeMergeCallback = null): bool
    {
        // Implementation includes:
        // - Changelog detection (checks file modification times)
        // - Content transformation via callback
        // - Atomic file writing
        // - Error handling
    }
}
```

**Key Features:**

- Only merges when source files have changed (performance optimization)
- Supports callbacks for content transformation before merging
- Handles file locking and atomic writes
- Extensible via inheritance

### Cache Implementation

[](#cache-implementation)

Provides efficient caching for optimization artifacts:

```
class Cache implements CacheInterface
{
    /**
     * Store content in cache
     *
     * @param string $key Cache key
     * @param string $content Content to cache
     * @return bool Success status
     */
    public function set(string $key, string $content): bool;

    /**
     * Retrieve content from cache
     *
     * @param string $key Cache key
     * @return string|null Cached content or null if not found
     */
    public function get(string $key): ?string;
}
```

**Features:**

- Size limit enforcement
- Automatic cleanup of old entries
- Fast lookup and retrieval

### URL &amp; Path Management

[](#url--path-management)

Handles complex URL-to-filesystem-path conversions:

```
class GetLocalPathFromUrl implements GetLocalPathFromUrlInterface
{
    /**
     * Convert URL to local filesystem path
     *
     * @param string $url Absolute or relative URL
     * @return string|null Local filesystem path or null if not resolvable
     */
    public function execute(string $url): ?string
    {
        // Handles:
        // - Absolute URLs (https://example.com/file.js)
        // - Relative URLs (/file.js)
        // - Protocol-relative URLs (//example.com/file.js)
        // - Media URLs, static URLs, pub URLs
        // - Validates internal vs external URLs
    }
}
```

### HTML Finders

[](#html-finders)

Efficient HTML parsing to locate resources:

```
class Js implements JsInterface
{
    /**
     * Find all JavaScript tags in HTML
     *
     * @param string $html HTML content
     * @return array Array of script tag information
     */
    public function findAll(string $html): array;
}

class Css implements CssInterface
{
    /**
     * Find all CSS link/style tags in HTML
     *
     * @param string $html HTML content
     * @return array Array of CSS tag information
     */
    public function findAll(string $html): array;
}
```

**Capabilities:**

- Regex-based HTML parsing
- Handles inline and external resources
- Preserves tag attributes
- Returns structured data for processing

Dependencies
------------

[](#dependencies)

- `magento/framework: *`
- `hryvinskyi/magento2-page-speed-api: 1.0.*`
- `ext-dom: *`
- `ext-simplexml: *`

Use Cases
---------

[](#use-cases)

This module is used by:

- CSS optimization modules for merging CSS files
- JavaScript optimization modules for merging JS files
- Lazy loading modules for HTML manipulation
- Any module requiring file merge or HTML parsing capabilities

Compatibility
-------------

[](#compatibility)

- Magento 2.3.x
- Magento 2.4.x
- PHP 7.4+
- PHP 8.0+
- PHP 8.1+

Support
-------

[](#support)

For issues, questions, or contributions:

- Email:
- GitHub:

License
-------

[](#license)

[MIT License](LICENSE)

Author
------

[](#author)

**Volodymyr Hryvinskyi**

- Email:

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~207 days

Recently: every ~119 days

Total

8

Last Release

31d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9294098?v=4)[Volodymyr Hryvinskyi](/maintainers/hryvinskyi)[@hryvinskyi](https://github.com/hryvinskyi)

---

Top Contributors

[![hryvinskyi](https://avatars.githubusercontent.com/u/9294098?v=4)](https://github.com/hryvinskyi "hryvinskyi (12 commits)")

### Embed Badge

![Health badge](/badges/hryvinskyi-magento2-page-speed/health.svg)

```
[![Health](https://phpackages.com/badges/hryvinskyi-magento2-page-speed/health.svg)](https://phpackages.com/packages/hryvinskyi-magento2-page-speed)
```

###  Alternatives

[elgentos/regenerate-catalog-urls

Regenerate Catalog URL Rewrites (products, categories, cms pages)

2842.6M](/packages/elgentos-regenerate-catalog-urls)[nosto/module-nostotagging

Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.

27703.7k4](/packages/nosto-module-nostotagging)[fishpig/magento2-wordpress-integration

Securely integrate WordPress and Magento 2.

83369.2k7](/packages/fishpig-magento2-wordpress-integration)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1860.2k](/packages/myparcelnl-magento)[loki/magento2-components

Core module for defining Alpine.js components with advanced AJAX features

1011.8k26](/packages/loki-magento2-components)[mage-os/module-rma

Return Merchandise Authorization

193.3k](/packages/mage-os-module-rma)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
