Minify put CSS and JS compression and cut

Source: Internet
Author: User
Tags vars

Minify CSS and JS compression and reduction (minify: Remove the space carriage, etc.), and the integration of multiple CSS,JS files into a file. Do not assume that your large bandwidth does not need to be optimized for this type of optimization. The reason to use it more importantly is file merging, not compression, but file consolidation, which can reduce the browser to constantly make new connection requests, like the FTP server, multiple small files and a large file time is not the same.

Minify is written in PHP, project address http://code.google.com/p/minify/

installation
1. Download the latest minify and unzip to the Minify directory.
2. Copy the "min" Directory to your document_root.

Basic Usage
Suppose you have a http://localhost/a.js,http://localhost/b.js of two files. So now, you can use Http://localhost/min/?f=a.js,b.js to see if the browser returns results, is not the content of the Minify two JS file?

README.txt under the directory of Min

Reference
The files in this directory contain the default minify settings, which are designed to simplify the consolidation of your site. Minify will combine to cut JavaScript or CSS files and make HTTP compression and cache headers.

Recommended
It is recommended to modify config.php to set $min_cachepath to a PHP writable directory. This will improve performance.

GETTING STARTED
The quickest way to start minify is to use the URI of the Minify builder application
Visit your website: http://example.com/min/builder/

Compress a single file
For example, you need 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 from the Web root path (no path required/) ". Because CSS files may contain relative uri,minify, they are automatically found through the override mechanism.

merging multiple files to a file 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 combine them with minify:
Http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js

simplifying the basic path
If you merge files that share the same parent directory, you can use the B parameter to set the base directory of the F parameter (also excluding the preamble or suffix/character).
For example, the following two ways of writing 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

using minify in HTML
In the (X) HTML file, don't forget to replace & with &

Specify the allowed directories
By default, Minify does not have any *.css/*.js files in the Document_root range. If you want to restrict minify access to certain directories, set the config.php in the
$min _serveoptions [' Minapp '] [' allowdirs '] array. For example: Restricted to/js and/themes/default directories, using:
    1. $min _serveoptions['minapp ' [' allowdirs '] = Array ('//js ', '//themes/default ');


"groups": Faster performance and better URLs
For best performance, edit the pre-specified filegroups in groupsconfig.php, below is an example configuration:
    1. Return Array (
    2. ' js ' = = Array ('//js/class.js ', '//js/email.js ')
    3. );

The above pre-specified JS will result in merging 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: Specifying files other than the Document_root directory
In the groupsconfig.php array,//is pointing to Document_root, but you can also specify the absolute directory path from the system or relative to the Document_root directory:
    1. Return Array (
    2. ' js ' = = Array (
    3. '//js/file.js '//file within Doc_root
    4. ,'//. /file.js '//file in parent directory of Doc_root
    5. ,' c:/users/steve/file.js ' //file anywhere on filesystem
    6. )
    7. );

Future expired HTTP header
Minify can send future (one year) expired HTTP headers. To enable this feature, you must add a number to URIs (for example,/min/?g=js&1234 or/min/f=file.js&1234) to change the number 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:
    1. <?php
    2. Before making sure that the Min/lib directory is set to Include_path
    3. Add/min/lib to your include_path first!
    4. Require $_server[' Document_root '].   '/min/utils.php ';
    5. $jsUri = Minify_groupuri (' JS ');
    6. echo "<script type= ' text/javascript ' src= ' {$jsUri} ' ></script>";


Debug Mode
In debug mode, Minify does not compress the file, but instead sends the merged file with the line number. To enable this mode, set the $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 pattern, the comment-style string regular expression may cause problems.

Upload min directory to root directory, root directory open http://example.com/min/

Note: Please set $min_cachePath in/min/config.php to improve performance.

Set the/min/config.php file,$min_cachePath 有3个选择。

$min _cachepath = ' c://windows//temp ';
$min _cachepath = '/tmp ';
$min _cachepath = preg_replace ('/^//d+;/', ", Session_save_path ());

Select 2nd, remove//. Set the TMP property 777

Add the JS/CSS path you want to merge in the displayed interface, and click ' Update ' to generate a URL for you, such as:http://localhost/min/b=googletesting/js& F=mootools.js, Iaction.js,iajax.js,global.js

CSS and JS merge separately, 2 addresses. If you need to combine a lot of files, the URL will become very long, minify support Group, you can group these files, so that the URL only need to specify the G=group name.

Delete the min/builder/index.php file after the installation is complete. Prevent others from landing! Edit upload again later if necessary!

Minify put CSS and JS compression and cut

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.