Open source work-JS and CSS file compression tool written in PHP-SuMinify_PHP_1_5

WBOY
Release: 2016-08-08 09:22:29
Original
1248 people have browsed it

Foreword:

Website projects need to reference external files to reduce loading traffic, and after loading the external resource file for the first time, if other pages with the same domain name reference the same address, you can use the browser cache to directly read the local cached resource file , without the need to download the same external resource file for each page. Some of the external resource files are third-party plug-ins, and some are business function scripts written by myself. When projects reference these external files, they need to compress the uncompressed third-party plug-ins before citing them. Some of their own business function scripts are In the form of a plug-in, referencing a functional script requires referencing several script files at the same time. Therefore, these script files need to be merged into a compressed file and then referenced. This can reduce the number of HTTP requests and reduce the loading traffic of these external resource files.
In order to achieve these goals, my original steps were: Create a new .min.xxx file in the target path. Open a website that provides online js/css compression services, copy the source code into the online compression, then copy it out and paste it to .min. xxx files, if you need to merge files, copy, compress and paste the source codes of multiple files into the same .min.xxx file. However, as the project progresses, there are more and more functions, and more and more files need to be referenced. Every time an external source file is changed, a lot of effort is required to update the .min.xxx file, especially the source file. They are distributed in different directories, and it is quite troublesome to find these directories. So I came up with the idea of ​​making a small program that automates compression and merging. As long as I run this program, it can help me complete these tedious repetitive tasks.

Introduction:
SuMinify_PHP is a single-file green version of PHP program used to compress or merge js files or css files in website projects. Like phpinfo.php, it can be easily used in projects.
In the process of developing website projects, js files are often distributed in different directories, such as third-party plug-ins, self-written plug-ins, etc. Generally, multiple Javascript plug-ins are compressed and merged into one file for project reference to reduce the number of The number of http requests.
If you operate it manually, you will have to spend a lot of effort to compress and merge files every time the plug-in is changed. With this automated program, you can write the external resource files in the project into an automated configuration according to the rules, and then change the file every time Then, as long as you run the SuMinify program, it can help you compress or merge files into the specified directory according to the rules, saving you laborious physical labor and improving work efficiency~

Features:
1. Single-file green version, no external Dependent, convenient for deployment and use
2. Supports quick switching of multiple projects
3. Write the configuration file according to the rules, and can automatically read the source code from the source code path according to the configuration file and compress it, and output it to the specified .min compressed file
4 , the project's rule configuration file can be placed in any path
5. Merge the contents of multiple files in different directories into one file
6. Perform in-place batch compression of the entire directory. For example, if there are several files in the directory, as long as After filling in the directory path, you can automatically traverse the files in the directory and generate compressed files in the format of each file name + .min. suffix
7. After compressing the resource files in the entire directory, merge them into a specified path .min file
8. When the entire directory is batch compressed in place, the .min file is automatically ignored to prevent repeated compression

Usage:
1. Copy the SuMinify_PHP_1_5 file to any directory in your project (this file is a single file Green version, easy to use^_^).
2. Modify the configuration content to the rules that suit your needs.
3. Run this file. After the generation is successful, you can view and use your results~

Help:

<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

Running renderings:

Homepage: http://git.oschina.net/sutroon/SuMinify_PHP_1_5

Source code: https://git.oschina.net/sutroon/SuMinify_PHP_1_5.git

The above has introduced the open source work - SuMinify_PHP_1_5, a JS and CSS file compression tool written in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template