: This article mainly introduces the open-source file-JS and CSS file compression tool written in PHP-SuMinify_PHP_1_5. if you are interested in the PHP Tutorial, please refer to it. Preface:
A website project must reference an external file to reduce the load traffic. after loading an 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 local cached resource files without downloading the same external resource files on each page. Some external resource files are third-party plug-ins, and some are self-written business function scripts. if the project references these external files, compress the uncompressed third-party plug-ins before referencing them, some of their own business function scripts are made into plug-ins. to reference a function script, you must reference several script files at the same time. Therefore, you need to combine these script files into a compressed file and then reference it, this reduces the number of HTTP requests and the loading traffic of these external resource files.
In order to achieve these goals, the original step is to create a new path in the target path. min. file xxx open the website that provides online js/css compression services, copy the source code to online compression, copy it, and paste it. min. xxx file. to merge files, copy, compress, and paste the source code of multiple files to the same one. min. xxx file. However, as the project progresses, more and more functions and more files need to be referenced, each time an external source file is changed, a lot of effort is required. min. the xxx file is updated, especially when the source files are distributed in different directories. it is effort-consuming to find these directories. So I came up with the idea of creating a small program for automated compression and merging. as long as I run this program, it will help me to complete these tedious repetitive tasks.
Introduction:
SuMinify_PHP is a single-file Green PHP program used to compress or merge js files or css files in website projects. it can be used in projects just like phpinfo. php.
During website project development, js files are often distributed in different directories, such as third-party plug-ins and self-written plug-ins, generally, multiple Javascript plug-ins are compressed and merged into one file for reference by the project to reduce the number of http requests.
If you perform manual operations, it takes a lot of effort to compress and merge files every time the plug-in changes. with this automation program, you can write the project's external resource file into an automatic configuration according to the rules. after each file change, as long as you run the SuMinify program, you can compress or merge the files to the specified directory according to the rules, it saves effort and improves work efficiency ~
Features:
1. single-file Green edition with no external dependencies, facilitating deployment and use
2. supports fast switching between multiple projects
3. write the configuration file according to the rules. the configuration file can automatically read and compress the source code from the source code path and output the file to the specified. min compressed file.
4. The rule configuration file of the project can be stored in any path.
5. merge the contents of multiple files in different directories into one file.
6. batch compress the entire directory. for example, if there are several files in the directory, you only need to fill in the directory path to automatically traverse the files in the directory and use each file name +. min. format of the suffix to generate compressed files
7. compress the resource files in the entire directory and merge them into a. min file in the specified path.
8. during local batch compression of the entire directory, 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 for ease of use ^_^ ).
2. modify the configuration content to meet your needs.
3. run this file. after the file is generated successfully, you can view and use your results ~
Help:
$ Config = array (// soui_v3a project 'soui _ v3a '=> 'F: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ soui_v3a_config.php ', // soui_v3b project 'soui _ v3b '=> array ('js' => array ('in-place-minify' => array (// Local compression js 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Javascript \ superfish. JS', // Generate superfish in the local directory. min. js file array ('path' => 'F: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Javascript \ Pages \ * ', 'skips' => array ('F: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Javascript \ Pages \ skip-me1.js ', 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Javascript \ Pages \ skip-me2.js ')), // Local compression of the entire directory, skipping the compression of two files), 'f: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Javascript \ min \ jquery. easyui. min. js '=> array ('path' => 'F: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Javascript \ easyui \ jquery. easyui. min. JS', 'minify '=> false), // without compression, directly merge 'f: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Javascript \ easyui \ locale \ easyui-lang-zh_CN.js ', // merge after compression), 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Javascript \ min \ pages. min. js' => array ('path' => 'F: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Javascript \ Pages \*'), // compress all files in the directory and merge the files 'f: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Javascript \ js-prototype-extension.js '. // compress the files and merge the files 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Plugin \ jquery-audioplayer-1.0 \ jquery-audioPlayer-1.0.js ', // merge after compression )), 'css '=> array ('in-place-minify' => array (// compress css in place 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Css \ Pages \ * ', // Local compression of the entire directory), 'f: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Css \ jeasyui \ Default \ easyui.min.css '=> array ('F: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Css \ jeasyui \ Default \ easyui.css ', // merge array ('path' => 'F: \ OpenOpus \ suminify_php_00005 \ Example \ Resfile \ Css \ jeasyui \ icon.css ', 'replaces' => array ("'icons'/" => "'.. /Icons/"), // compress and replace the content, then merge), 'f: \ OpenOpus \ Alibaba \ Example \ Resfile \ Css \ superfish \ superfish.min.css '=> array ('F: \ OpenOpus \ SuMinify_PHP_1_5 \ Example \ Resfile \ Css \ superfish \ superfish.css ', // Local compression ),)),);
Run:
Home: http://git.oschina.net/sutroon/SuMinify_PHP_1_5
Source code: https://git.oschina.net/sutroon/SuMinify_PHP_1_5.git
The above introduces the open-source file-JS and CSS file compression tool written in PHP-SuMinify_PHP_1_5, including some content, and hopes to help friends who are interested in PHP tutorials.