Download the PHP package ctw/ctw-middleware-htmlminifier without Composer

On this page you can find all versions of the php package ctw/ctw-middleware-htmlminifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ctw-middleware-htmlminifier

Package "ctw/ctw-middleware-htmlminifier"

Latest Stable Version GitHub Actions Scrutinizer Build Scrutinizer Quality Code Coverage

PSR-15 middleware that minifies HTML responses using pluggable adapters, reducing bandwidth and improving page load times.

Introduction

Why This Library Exists

HTML generated by template engines often contains excessive whitespace, comments, and formatting that increases page size without benefiting end users. Minifying HTML at the response level provides several advantages:

This middleware intercepts HTML responses and minifies them transparently, with multiple adapter options to balance speed versus compression ratio.

Problems This Library Solves

  1. Bloated HTML: Template engines produce readable but unnecessarily large output
  2. Manual optimization: Without automation, developers must manually minify HTML
  3. Inconsistent minification: Different approaches across a codebase lead to varying output quality
  4. Build complexity: Template-level minification complicates the build process
  5. Debugging difficulty: Aggressive minification can break HTML; adapters provide different safety levels

Where to Use This Library

Design Goals

  1. Pluggable adapters: Choose the right minification strategy for your needs
  2. Safe defaults: Conservative minification that won't break valid HTML
  3. Transparent operation: Works automatically on HTML responses only
  4. Statistics tracking: Appends an HTML comment showing compression ratio
  5. Zero template changes: Minifies at response level, not template level

Requirements

Installation

Install by adding the package as a Composer requirement:

Usage Examples

Basic Pipeline Registration (Mezzio)

ConfigProvider Registration

Available Adapters

Adapter Description Speed Compression
SimpleAdapter Regex-based whitespace removal Fast Moderate
TidyAdapter Uses PHP's Tidy extension for safe minification Medium Good
WyriHaximusAdapter Full-featured HTML compressor (requires additional package) Slower Best

Using SimpleAdapter

The SimpleAdapter uses regular expressions for fast, lightweight minification:

Performs:

Using TidyAdapter

The TidyAdapter leverages PHP's Tidy extension for standards-compliant minification:

Features:

Using WyriHaximusAdapter

For maximum compression, install the optional dependency:

Output Statistics

The middleware appends an HTML comment showing compression statistics:

Field Description
in Original HTML size in bytes
out Minified HTML size in bytes
diff Percentage reduction achieved

Selective Processing

The middleware automatically:


All versions of ctw-middleware-htmlminifier with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ext-tidy Version *
ctw/ctw-middleware Version ^5.0
psr/container Version ^1.0 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ctw/ctw-middleware-htmlminifier contains the following files

Loading the files please wait ...