mechanik/laminas-turbo-speed

Laminas Turbo Speed 模块

dev-master 2021-04-01 20:08 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:49 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

描述

一个开箱即用的模块,通过最小化/压缩HTML内联内容和通过HTTP/2推送资源来提升你的Laminas网站性能。目前此模块适用于HTML5类型,请不要与XHTML一起使用。

当前功能

  • 通过ListenerAggregateInterface注册的事件
  • 轻松开启/关闭任何特定功能或整个模块
  • 能够强制所有路由使用HTTPS(通过onRoute)
  • 能够最小化内联JavaScript(移除注释和空格)
  • 能够最小化内联样式表(移除注释、空格、CDATA、换行符)
  • 能够最小化HTML(移除注释、空格、换行符)
  • 能够通过HTTP/2推送脚本
  • 能够通过HTTP/2推送样式表
  • 能够通过HTTP/2推送图片
  • PHP 7兼容(并且推荐)
  • 不会“破坏”你的页面/内容
  • 超快处理,无CPU开销(正则表达式模式已优化以非常快)
  • 没有其他依赖(除了Laminas)

计划中的功能

  • 通过Redis进行缓存
  • 通过Memcached进行缓存
  • 通过CDN(推送/拉取)进行缓存
  • 更好的HTML、JS、CSS最小化
  • 更多...

安装

安装通过Composer完成

composer require mecanik/zf3turbo

模块配置

创建config/autoload/laminas-turbo-speed.global.php,并添加以下内容

<?php
return [
    'turbolaminas' => [
        // Completely enable/disable all functionality
        'enabled' => true,

        // Control current engine options
        'engine_options' => [

            // Force all routes to https:// and choose redirect http code
            // Recommended redirect_code is 301
            'ssl' => [
                'enabled' => false,
                'redirect_code' => 301,
            ],

            'html_minifier' => [

                // Completely enable/disable all functionality
                'enabled' => true,

                // remove HTML comments (not containing IE conditional comments)
                // Recommended: true
                'remove_comments' => true,

                // remove whitespaces and line breaks
                // Recommended: true
                'remove_whitespaces' => true,

                // remove trailing slash from void elements
                // Optional
                'remove_trailing_slashes' => true,
            ],

            // Soon...
            'html_cache' => [],

            'css_minifier' => [

                // Completely enable/disable all functionality
                'enabled' => true,

                // This will minify inline <style></style> tags, will strip comments and white spaces and new lines.
                // Warning: Might break some styles, use with caution.
                'minify_inline_styles' => true,
            ],

            'js_minifier' => [

                // Completely enable/disable all functionality
                'enabled' => false,

                // This will minify inline <script></script> tags, will strip comments and white spaces and new lines.
                // Warning: Might break some styles, use with caution.
                'minify_inline_js' => true,
            ],

            // Push assets via HTTP/2 to the browser
            'http2_push' => [

                // Completely enable/disable all functionality
                'enabled' => true,

                // Push all local CSS files via HTTP/2
                'push_css' => true,

                // Push all local JS files via HTTP/2
                'push_js' => true,

                // Push all local IMG files via HTTP/2
                'push_images' => true,
            ],
        ],
        
        // Show some love ? :x (will add a header in the response request, only devs will see it...)
        'show_credits' => true,
    ],
];

模块使用

加载模块(按任何顺序)

'Mecanik\LaminasTurboSpeed'

关于HTTP/2的说明

你必须对HTTP/2推送的工作原理有一个基本的了解。也就是说,它只会推送位于你自己的网站上的资源,基础URL为“public”或“public_html”。(目前如此)

这就是现在的所有内容,祝您享受!