项目作者: middlewares

项目描述 :
Middleware to minify Html, CSS and Javascript responses
高级语言: PHP
项目地址: git://github.com/middlewares/minifier.git
创建时间: 2016-10-10T15:42:44Z
项目社区:https://github.com/middlewares/minifier

开源协议:MIT License

下载


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.

  1. composer require middlewares/minifier

Example

  1. Dispatcher::run([
  2. Middlewares\Minifier::html(),
  3. Middlewares\Minifier::css(),
  4. Middlewares\Minifier::js(),
  5. ]);

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).

  1. use WyriHaximus\HtmlCompress\Factory;
  2. $compressor = Factory::construct();
  3. $mimeType = 'text/html';
  4. $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.

  1. $streamFactory = new MyOwnStreamFactory();
  2. $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:

  1. $htmlMinifier = Middlewares\Minifier::html();
  2. $cssMinifier = Middlewares\Minifier::css();
  3. $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.