Table of Contents
开源作品-PHP写的JS和CSS文件压缩利器-SuMinify_PHP_1_5,
Home php教程 php手册 开源作品-PHP写的JS和CSS文件压缩利器-SuMinify_PHP_1_5,

开源作品-PHP写的JS和CSS文件压缩利器-SuMinify_PHP_1_5,

Jun 13, 2016 am 09:01 AM
c css php work sharp weapon compression and Open source document

开源作品-PHP写的JS和CSS文件压缩利器-SuMinify_PHP_1_5,

前言:

网站项目需要引用外部文件以减小加载流量,而且第一次加载外部资源文件后,其他同域名的页面如果引用相同的地址,可以利用浏览器缓存直接读取本地缓存资源文件,而不需要每个页面都下载相同的外部资源文件。外部资源文件有一些是第三方插件,有一些是自己写的业务功能脚本,项目引用这些外部文件,需要把没有压缩过的第三方插件压缩后再引用,而自己的业务功能脚本,有的做成插件形式,引用一个功能脚本,需要同时引用若干个脚本文件,因此需要把这些脚本文件合并成一个压缩文件再引用,这样可以减少HTTP请求次数,减少这些外部资源文件的加载流量。
为了实现这些目标,自己原来的步骤是:在目标路径新建.min.xxx文件 》 打开提供在线js/css压缩服务的网站,把源码复制进去在线压缩,然后拷贝出来,粘帖到.min.xxx文件, 如果需要合并文件,则把多个文件的源码复制,压缩,粘帖到同一个.min.xxx文件。但是随着项目的进展,功能越来越多,需要引用的文件也越来越多,每次改动一个外部源文件,都要折腾很多精力才能把.min.xxx文件更新好,特别是源文件分布在不同的目录下,为了寻找这些目录也是挺费心的。所以产生了做一个自动化压缩合并的小程序的想法,只要运行这个程序,就能帮我把这些繁琐的重复劳动完成。

 

简介:
SuMinify_PHP是一个用于压缩或合并网站项目中的js文件或css文件的单文件绿色版PHP程序,和phpinfo.php一样可以方便放到项目中使用。
开发网站项目过程中,js文件经常是分布在各个不同的目录中,如第三方插件、自己写的插件等,一般会把多个Javascript插件压缩后合并到一个文件中供项目引用,以减少http请求次数。
如果手工操作,每次插件改动的时候,都要花费很多精力来压缩和合并文件,有了这个自动化程序,就可以把项目中的外部资源文件根据规则写成一个自动化配置,然后每次改动文件后,只要运行SuMinify程序,就可以根据规则帮你把文件压缩或合并到指定目录,省去了费心费力的体力劳动,提高了工作效率~

特性:
1、单文件绿色版,无外部依赖,方便部署使用
2、支持多个项目快速切换
3、根据规则写好配置文件,能根据配置文件自动从源码路径中读取源码并压缩,输出到到指定的.min压缩文件
4、项目的规则配置文件能放再任意路径中
5、合并不同目录中的多个文件的内容到一个文件中
6、对整个目录进行就地批量压缩,比如目录中有若干文件,则只要填好目录路径,就能自动遍历目录中的文件,并以每个文件名+.min.后缀的格式生成压缩后的文件
7、将整个目录的资源文件进行压缩后,合并到一个指定路径的.min文件中
8、整个目录就地批量压缩的时候,自动忽略.min文件,防止重复压缩

使用:
1. 将SuMinify_PHP_1_5文件复制到您的项目中任意目录(本文件为单文件绿色版,方便使用^_^).
2. 修改配置内容为适合您需要的规则.
3. 运行本文件,生成成功后,就可以查看并使用您的成果了~

帮助: 

<span>$config</span> = <span>array</span><span>(
    </span><span>//</span><span> soui_v3a项目</span>
    'soui_v3a' => 'F:\OpenOpus\SuMinify_PHP_1_5\Example\soui_v3a_config.php',
    <span>//</span><span> soui_v3b项目</span>
    'soui_v3b' => <span>array</span><span>(
        </span>'js' => <span>array</span><span>(
            </span>'in-place-minify' => <span>array</span>(<span>//</span><span> 就地压缩js</span>
                'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\superfish\superfish.js', <span>//</span><span> 就地生成superfish.min.js文件</span>
                <span>array</span>('path' => 'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\Pages\*', 'skips' => <span>array</span>('F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\Pages\skip-me1.js', 'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\Pages\skip-me2.js')), <span>//</span><span> 整个目录就地压缩,跳过其中2个文件的压缩</span>
            ),
            'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\min\jquery.easyui.min.js' => <span>array</span><span>(
                </span><span>array</span>('path' => 'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\easyui\jquery.easyui.min.js', 'minify' => <span>false</span>), <span>//</span><span> 不用压缩,直接合并</span>
                'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\easyui\locale\easyui-lang-zh_CN.js', <span>//</span><span> 压缩后合并</span>
            ),
            'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\min\pages.min.js' => <span>array</span><span>(
                </span><span>array</span>('path' => 'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\Pages\*'), <span>//</span><span> 将目录中所有文件压缩后合并</span>
                'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Javascript\js-prototype-extension.js', <span>//</span><span> 压缩后合并</span>
                'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Plugin\jquery-audioplayer-1.0\jquery-audioPlayer-1.0.js', <span>//</span><span> 压缩后合并</span>
<span>            )
        )</span>,
        'css' => <span>array</span><span>(
            </span>'in-place-minify' => <span>array</span>(<span>//</span><span> 就地压缩css</span>
                'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\Pages\*', <span>//</span><span> 整个目录就地压缩</span>
            ),
            'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\jeasyui\Default\easyui.min.css' => <span>array</span><span>(
                </span>'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\jeasyui\Default\easyui.css', <span>//</span><span> 压缩后合并</span>
                <span>array</span>('path' => 'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\jeasyui\icon.css', 'replaces' => <span>array</span>("'icons/" => "'../Icons/")), <span>//</span><span> 压缩后替换内容,然后合并</span>
            ),
            'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\superfish\superfish.min.css' => <span>array</span><span>(
                </span>'F:\OpenOpus\SuMinify_PHP_1_5\Example\Resfile\Css\superfish\superfish.css', <span>//</span><span> 就地压缩</span>
            ),<span>
        )
    )</span>,<span>
);</span>
Copy after login

 

运行效果图:

 

主页:http://git.oschina.net/sutroon/SuMinify_PHP_1_5

源码:https://git.oschina.net/sutroon/SuMinify_PHP_1_5.git

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? Apr 05, 2025 pm 10:33 PM

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

How to select a child element with the first class name item through CSS? How to select a child element with the first class name item through CSS? Apr 05, 2025 pm 11:24 PM

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

How to make multiple lines of text aligned and underscore with CSS? How to make multiple lines of text aligned and underscore with CSS? Apr 05, 2025 pm 08:00 PM

How to make multiple lines of text aligned and underscore with CSS? In daily web design, we often need to style multiple lines of text in special styles...

How to adjust hover style and logic of merged rows in el-table in Element UI? How to adjust hover style and logic of merged rows in el-table in Element UI? Apr 05, 2025 pm 07:45 PM

How to adjust the hover style and logic of merged rows in el-table? Using Element...

How to use react-transition-group to achieve the effect of tightly sliding switching of React components from right to left? How to use react-transition-group to achieve the effect of tightly sliding switching of React components from right to left? Apr 05, 2025 pm 08:03 PM

Regarding the problem of using react-transition-group to achieve component switching transition effect in React. When using React development projects, we often need to implement some streams...

How to customize the hover effect of merge rows in el-table? How to customize the hover effect of merge rows in el-table? Apr 05, 2025 pm 06:54 PM

How to customize the hover effect of merge rows in el-table? Using Element...

Why do two inline-block elements show misalignment? How to solve this problem? Why do two inline-block elements show misalignment? How to solve this problem? Apr 05, 2025 pm 08:09 PM

Discussing the reasons for misalignment of two inline-block elements. In front-end development, we often encounter element typesetting problems, especially when using inline-block...

Why does a specific div element in the Edge browser not display? How to solve this problem? Why does a specific div element in the Edge browser not display? How to solve this problem? Apr 05, 2025 pm 08:21 PM

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

See all articles