Home > Backend Development > PHP Tutorial > Open source work-JS and CSS file compression tool written in PHP-SuMinify_PHP_1_5, _PHP tutorial

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

WBOY
Release: 2016-07-13 09:50:00
Original
999 people have browsed it

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

Foreword:

Website projects need to reference external files to reduce loading traffic. After the external resource file is loaded for the first time, if other pages with the same domain name refer to the same address, the browser cache can be used to directly read the local cached resource file. There is no need to download the same external resource files for every 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 and compress it online, then copy it out and paste it into. min.xxx file, 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 for automated 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 http requests.
If done manually, every time the plug-in is changed, a lot of effort will be spent on compressing and merging files. With this automated program, the external resource files in the project can be written into an automated configuration according to the rules, and then every time After modifying the file, just run the SuMinify program and it will help you compress or merge the files into the specified directory according to the rules, eliminating laborious physical labor and improving work efficiency~

Features:
1. Single-file green version, no external dependencies, easy to deploy and use
2. Supports quick switching of multiple projects
3. Write configuration files according to rules, and can automatically Read the source code from the source code path 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 a file
6. Perform in-place batch compression of the entire directory. For example, if there are several files in the directory, as long as the directory path is filled in, the files in the directory will be automatically traversed and each file name.min. The suffix format generates compressed files
7. After compressing the resource files of the entire directory, merge them into a .min file with a specified path
8. When the entire directory is compressed in batches, it will be automatically ignored. min file 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 suit your needs Rules.
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

Operation rendering:

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1018845.htmlTechArticleOpen source work-JS and CSS file compression tool written in PHP-SuMinify_PHP_1_5, Foreword: Website projects need to reference external files to Reduce loading traffic, and after loading external resource files for the first time,...
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