Minify compresses JS and CSS, and Minify compresses JSCSS.
Minify compresses and compresses CSS and JS (Minify: removes space return characters), and integrates multiple CSS and JS files into one file. Do not consider that such optimization is unnecessary for your large bandwidth. The reason for using it is more important to merge files, rather than compression, but file integration. This can reduce the number of new connection requests sent by the browser, just like the FTP server, multiple small files and a large file consume different time.
Minify is written in PHP, the Project address http://code.google.com/p/minify/
Installation
1. download the latest Minify and decompress it to the minify directory.
2. Copy the "min" directory to your DOCUMENT_ROOT.
Basic usage
Suppose you have two files: http: // localhost/a. js and http: // localhost/B. js. Now, you can use http: // localhost/min /? F = a. js, B. js. Check the result returned by the browser. Is it the content of the two js files of minify?
Readme.txt
Reference
Files in this directory contain the default Minify settings to simplify the integration of your website. Minify will merge and cut JavaScript or CSS files and perform HTTP compression and cache headers.
Recommendation
We recommend that you modify $ min_cachePath in config. php to a PHP writable directory. This will improve the performance.
GETTING STARTED
The fastest way to start Minify is to use the Minify Builder application URI.
Visit your Website: http://example.com/min/builder/
Compressing a single file
For example, you want to serve this file:
Http://example.com/wp-content/themes/default/default.css
The following is the "Minify URL" file:
Http://example.com/min? F = wp-content/themes/default/default.css
In other words, the "f" parameter is set to the target file under the WEB root path (no path/is required /)". Since CSS files may contain relative Uris, Minify will automatically find them through the rewrite mechanism.
Merge multiple files to one file for download
Use ',' to separate each file name of the f parameter.
For example, there are the following CSS files:
Http://example.com/scripts/jquery-1.2.6.js
Http://example.com/scripts/site.js
You can use Minify to combine:
Http://example.com/min? F = scripts/jquery-1.2.6.js, scripts/site. js
Simplified basic path
If the files you merge share the same parent directory, you can use the basic directory of the f parameter set by parameter B (excluding the leading or suffix/character ).
For example, the following two statements have the same effect:
Http://example.com/min? F = scripts/jquery-1.2.6.js, scripts/site. js, scripts/home. js
Http://example.com/min? B = scripts & f = jquery-1.2.6.js, site. js, home. js
Use MINIFY in Html
In the (X) HTML file, do not forget to replace & with & amp;
Specify the allowed directory
By default, Minify does not have any *. css/*. js files in the DOCUMENT_ROOT range. If you want to restrict Minify from accessing some directories, Set
$ Min_serveOptions ['minapp'] ['allowdirs'] array. For example, to restrict the/js and/themes/default directories, use:
Php code
- $ Min_serveOptions ['minapp'] ['lowdirs'] = array ('// js',' // themes/default ');
"Group": faster performance and better Web Site
To achieve optimal performance, edit the pre-specified file group in groupsConfig. php. The following is an example Configuration:
Php code
- Return array (
- 'Js' => array ('// js/Class. js',' // js/email. js ')
- );
The preceding pre-specified js merges the result into the following files:
Http://example.com/js/Class.js
Http://example.com/js/email.js
Now you can simplify the URL:
Http://example.com/min? G = js
GROUP: Specify files other than the document_root directory
In the groupsConfig. php array, // indicates DOCUMENT_ROOT, but you can also specify the absolute directory path from the system or the relative directory relative to document_root:
Php code
- Return array (
- 'Js' => array (
- '// Js/file. js' // file within DOC_ROOT
- , '// ../File. js' // file in parent directory of DOC_ROOT
- , 'C:/Users/Steve/file. js' // file anywhere on filesystem
- )
- );
HTTP header expired in the future
Minify can send HTTP headers that expire in the future (one year. To enable this function, you must add a number to URIs (for example,/min /? G = js & 1234 or/min/f = file. js & 1234). This number is changed whenever the source file is modified. If you use SVN/CVS, you can consider using the revision number as the number.
If you use "group" to merge and compress your files, you can use the tool function Minify_groupUri () to get a "version" URI. For example:
Php code
- <? Php
- // Make sure that the min/lib directory is set to include_path.
- // Add/min/lib to your include_path first!
- Require $ _ SERVER ['document _ root']. '/min/utils. php ';
- $ JsUri = Minify_groupUri ('js ');
- Echo "<script type = 'text/javascript 'src = '{$ jsUri}'> </script> ";
Debugging mode
In debugging mode, Minify does not compress the file, but sends the merged file with a row number. To enable this mode, set $ min_allowDebugFlag to true in config. php and add "& debug = 1" to your URIs.
Example:/min /? F = script1.js, script2.js & debug = 1
Note: For this mode, a comment-style string regular expression may cause problems.
For more questions, visit the http://groups.google.com/group/minify
I used the Minify plug-in IIS to compress css and JS. Why is an error prompted?
There are two ways to use Minify: one is to set the groupconfig file in min, and the other is to write the address and the last one in a url. You can check whether the minify pseudo-static block can be used and the config file. Php. Generally, this problem is related to the path settings in the configuration.
How to compress css and js files for fast transmission?
We all know that bluehost supports Gzip compression, but there is no obvious enable button to be configured by yourself. However, one disadvantage of Gzip is that it cannot compress css and js files, but it does not mean that these two files cannot be compressed as html files. We can use a library named Minify for compression.
Usage: 1. Download Minify
2. decompress the package and upload the min file to the root directory of the website.
3. Write the. htaccess file and add the following code: