You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/middlewares/minifier

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/middlewares/minifier

v2.1.0+incompatible
Source
Go
Version published
Created
Source

middlewares/minifier

Latest Version on Packagist Software License Testing Total Downloads

Middleware to minify the Html, CSS and Javascript content using wyrihaximus/compress and the following compressors by default:

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/minifier.

composer require middlewares/minifier

Example

Dispatcher::run([
    Middlewares\Minifier::html(),
    Middlewares\Minifier::css(),
    Middlewares\Minifier::js(),
]);

Usage

This middleware minify the code of http responses using any compressor implementing the WyriHaximus\Compress\CompressorInterface. The code format is detected from the Content-Type header, so make sure your responses contains this header (you may want to use middlewares/negotiation for that).

use WyriHaximus\HtmlCompress\Factory;

$compressor = Factory::construct();
$mimeType = 'text/html';

$minifier = new Middlewares\Minifier($compressor, $mimeType);

Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface as third argument to create the response body. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$streamFactory = new MyOwnStreamFactory();

$minifier = new Middlewares\Minifier($compressor, $mimeType, $streamFactory);

Helpers

Three static functions are provided to create instances of this middleware with common configuration for html, css and js responses:

$htmlMinifier = Middlewares\Minifier::html();
$cssMinifier = Middlewares\Minifier::css();
$jsMinifier = Middlewares\Minifier::js();

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

FAQs

Package last updated on 23 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.