PHPackages                             reeteshjee/minifyone - 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. reeteshjee/minifyone

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

reeteshjee/minifyone
====================

A PHP library to combine and minify CSS/JS files into a single file for fewer HTTP requests.

1.0.0(7mo ago)43MITPHPPHP &gt;=7.4

Since Oct 2Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/reeteshjee/minifyone)[ Packagist](https://packagist.org/packages/reeteshjee/minifyone)[ RSS](/packages/reeteshjee-minifyone/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

MinifyOne
=========

[](#minifyone)

**MinifyOne** is a simple and lightweight PHP library to **combine** and **minify** multiple CSS or JavaScript files into a **single optimized file**.
It helps reduce the number of HTTP requests, improving page load speed and performance.

---

🚀 Features
----------

[](#-features)

- ✅ Combine multiple CSS or JS files into one.
- ✅ Basic minification to reduce file size.
- ✅ Caching based on file hash — no unnecessary reprocessing.
- ✅ Option to directly serve the file with correct headers.
- ✅ Easy to integrate in any PHP project.
- ✅ Works with Composer for easy installation.

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require reeteshjee/minifyone
```

Or manually include the `src/MinifyOne.php` file in your project.

---

🛠 Usage
-------

[](#-usage)

### 1️⃣ Combine Files and Get File Path

[](#1️⃣-combine-files-and-get-file-path)

```
require 'vendor/autoload.php';

use MinifyOne\MinifyOne;

// Create instance (output directory, enable/disable minify)
$minify = new MinifyOne(__DIR__ . '/cache', true);

// Combine JavaScript files
$combinedJs = $minify->combine(['assets/js/file1.js', 'assets/js/file2.js'], 'js');
echo "Combined JS: $combinedJs";

// Combine CSS files
$combinedCss = $minify->combine(['assets/css/style1.css', 'assets/css/style2.css'], 'css');
echo "Combined CSS: $combinedCss";
```

This will:

1. Combine the files.
2. Minify content (if enabled).
3. Store them in the specified cache folder.
4. Return the path to the combined file.

---

### 2️⃣ Combine and Serve Directly

[](#2️⃣-combine-and-serve-directly)

If you want to serve the combined file immediately in a request:

```
require 'vendor/autoload.php';

use MinifyOne\MinifyOne;

$minify = new MinifyOne(__DIR__ . '/cache');

// Output combined CSS directly to the browser
$minify->combineAndServe([
    'assets/css/style1.css',
    'assets/css/style2.css'
], 'css');
```

This will:

- Send the correct `Content-Type` header.
- Output the minified content.
- Send long cache headers (`max-age=31536000`).

---

### 3️⃣ Example with HTML

[](#3️⃣-example-with-html)

You can generate a combined file and use it in HTML:

```
require 'vendor/autoload.php';

use MinifyOne\MinifyOne;

$minify = new MinifyOne(__DIR__ . '/cache');

// Generate combined JS file
$combinedJs = $minify->combine([
    'assets/js/jquery.js',
    'assets/js/app.js'
], 'js');

// Generate combined CSS file
$combinedCss = $minify->combine([
    'assets/css/reset.css',
    'assets/css/main.css'
], 'css');
?>
