Middleware to minify the Html, CSS and Javascript content using wyrihaximus/compress

Overview

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.

You might also like...
Put your assets into the pipe and smoke them.

Pipe Put your assets into the pipe and smoke them. Pipe is an asset pipeline in the spirit of Sprockets. It's meant as the practical way for managing

NotrinosERP is an open source, web-based enterprise management system that written in PHP and MySql.
NotrinosERP is an open source, web-based enterprise management system that written in PHP and MySql.

NotrinosERP is an open source, web-based enterprise management system that written in PHP and MySql. NotrinosERP contains all the required modules for running any small to medium size businesses. It supports multi users, multi currencies, multi languages

Html Minifier adalah paket simpel untuk minify output Html, Css style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda.
Html Minifier adalah paket simpel untuk minify output Html, Css style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda.

Laravel Html Minifier Adalah Paket simpel untuk minify HTML, Css Style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda. Alat i

A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

PHP slim framework middleware to minify HTML output

slim-minify Slim middleware to minify HTML output generated by the slim PHP framework. It removes whitespaces, empty lines, tabs beetween html-tags an

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Complete Login and Registration system using HTML, CSS, JAVASCRIPT, BOOTSTRAP, PHP and MYSQL

Complete Login and Registration system using HTML, CSS, JAVASCRIPT, BOOTSTRAP, PHP and MYSQL

CakePHP Minify HTML Plugin

MinifyHtml CakePHP 4, HTML Minify Plugin Installation To install via Composer, use the command below, it will automatically detect the latest version

Rah cache minify - HTML compressor module for rah cache Textpattern CMS plugin

Minify module for rah_cache This is a minify module for rah_cache, a full-page caching solution for Textpattern CMS. Rah_cache_minify will minify HTML

A real-time chatting website using HTML, CSS, JavaScript, PHP
A real-time chatting website using HTML, CSS, JavaScript, PHP

ChatApp A real-time chatting website using HTML, CSS, JavaScript, PHP #Features Signup Login Signup & Login Validation Encrypted Password Realtime Mes

A FREE Wordpress Plugin to compress and convert images using cwebp, jpegoptim and optipng.
A FREE Wordpress Plugin to compress and convert images using cwebp, jpegoptim and optipng.

Squidge Is FREE WordpPress Plugin built for developers in mind compressing and convert images using jpegoptim, optipng, cwebp, and libavif. It's extre

A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

PHP CSS Parser A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output

Commenting program developed with Html & Css & Php JavaScript Languages ​​and MySql
Commenting program developed with Html & Css & Php JavaScript Languages ​​and MySql

CommentSystem [BETA] Commenting program developed with Html & Css & Php JavaScript Languages and MySql How does it work ? After you set up your Databa

Web application for the health record of the Hemal's Thalasseamia Patients. Technologies PHP, JavaScript, HTML, W3.CSS and MySQL

Web application for the health record of the Hemal's Thalasseamia Patients. Technologies PHP, JavaScript, HTML, W3.CSS and MySQL

Medical Master or
Medical Master or "Medic-M" was built to reduce the hassle of buying medicine, provide medicine to the sick in a short time. It is an HTML, CSS, JAVASCRIPT and PHP based system.

Medical Master (Medic-M) | WELCOME TO Medic-M(MEDICAL MASTER) | | Introduction | Medical Master or "Medic-M" was built to reduce the hassle of buying

A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire.
A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire.

Malzahar A magic PHP framework. Build reactive web apps without writing HTML, CSS, or JavaScript! Powered by Tailwind, Alpine, Laravel, & Livewire. Re

 Formulário de contato utilizando HTML, CSS, Bootstrap, PHP, Javascript e conexão ao banco de dados MySQL.
Formulário de contato utilizando HTML, CSS, Bootstrap, PHP, Javascript e conexão ao banco de dados MySQL.

Formulário de Contato Tecnologias | Projeto | Licença | 🚀 Tecnologias Esse projeto foi desenvolvido com as seguintes tecnologias: HTML CSS PHP JavaSc

Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.
Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.

StampGeek Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaSc

This is Fully Working Net Banking Project Developed in PHP, HTML, JavaScript, CSS
This is Fully Working Net Banking Project Developed in PHP, HTML, JavaScript, CSS

Net Banking Project in PHP In this project i have develop real world net-banking project. This project is a best simulator for banking learners Featur

Comments
  • Dependency patchwork/jsqueeze is abandoned

    Dependency patchwork/jsqueeze is abandoned

    Noticed that the error Package patchwork/jsqueeze is abandoned, you should avoid using it. No replacement was suggested. comes up when installing with composer. Looks like it a dependency of wyrihaximus/js-compress which is dependency of wyrihaximus/html-compress.

    I checked the composer.json file for WyriHaximus/php-js-compress and the current version seems to have already replaced patchwork/jsqueeze so I'm not sure if this is a version issue, but just wanted to point it out.

    opened by mav2287 7
  • Fix failed Quality assurance step

    Fix failed Quality assurance step

    Changed log

    • Using the "wyrihaximus/html-compress": "^2.0 || ^4.0" semver to be compatible with php-8.0 version. And resolving following errors:
    ou are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3.
    No lock file found. Updating dependencies instead of installing from lock file. Use composer update over composer install if you do not have a lock file.
    Loading composer repositories with package information
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.
    Error: Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - wyrihaximus/html-compress[2.0.0, ..., 2.0.1] require php ^7.2 -> your php version (8.0.0) does not satisfy that requirement.
        - Root composer.json requires wyrihaximus/html-compress ^2.0 -> satisfiable by wyrihaximus/html-compress[2.0.0, 2.0.1].
    
    
      Problem 1
        - wyrihaximus/html-compress[2.0.0, ..., 2.0.1] require php ^7.2 -> your php version (8.0.0) does not satisfy that requirement.
        - Root composer.json requires wyrihaximus/html-compress ^2.0 -> satisfiable by wyrihaximus/html-compress[2.0.0, 2.0.1].
    
    • Fixing the failed Quality assurance step during GitHub Action building.
    opened by peter279k 4
Owner
Middlewares
PSR-15 HTTP Middlewares
Middlewares
A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

PHP CSS Parser A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output

Raphael Schweikert 1.6k Jan 5, 2023
Commenting program developed with Html & Css & Php JavaScript Languages ​​and MySql

CommentSystem [BETA] Commenting program developed with Html & Css & Php JavaScript Languages and MySql How does it work ? After you set up your Databa

Azad 0 May 19, 2022
The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files.

Asset Component The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files. Res

Symfony 2.9k Jan 5, 2023
Combines. minifies, and serves CSS or Javascript files

Welcome to Minify! Minify is an HTTP server for JS and CSS assets. It compresses and combines files and serves it with appropriate headers, allowing c

Steve Clay 3k Jan 7, 2023
A fast Javascript minifier that removes unnecessary whitespace and comments

js-minify A fast Javascript minifier that removes unnecessary whitespace and comments Installation If you are using Composer, use composer require gar

Patrick van Bergen 5 Aug 19, 2022
Assets Manager for "Vitewind" Theme, will inject CSS and JS assets for "Vitewind" theme to work properly with viteJS in development and production

Vitewind Manager plugin ?? Windi CSS and ⚡️ Vite, for ?? OctoberCMS & ❄️ WinterCMS Introduction This is a helper plugin for ?? Vitewind theme, don't i

Adil Chehabi 4 May 29, 2022
Javascript Minifier built in PHP

JShrink JShrink is a php class that minifies javascript so that it can be delivered to the client quicker. This code can be used by any product lookin

Tedious Developments 678 Dec 31, 2022
PHP class to generate bookmarklets from Javascript code

Bookmarklet Gen Convert readable Javascript code into bookmarklet links Features removes comments compresses code by removing extraneous spaces, but n

྅༻ Ǭɀħ ༄༆ཉ 13 Oct 5, 2022
An asset compression plugin for CakePHP. Provides file concatenation and a flexible filter system for preprocessing and minification.

Asset Compress Asset Compress is CakePHP plugin for helping reduce the number of requests, and optimizing the remaining requests your application make

Mark Story 367 Jul 20, 2022
GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.

GLPI stands for Gestionnaire Libre de Parc Informatique is a Free Asset and IT Management Software package, that provides ITIL Service Desk features, licenses tracking and software auditing.

GLPI 2.9k Jan 2, 2023