Use Minify to optimize site performance

Source: Internet
Author: User
Tags website performance

Minify is an application developed with PHP5 that improves website performance by following some of Yahoo's optimization rules. It merges multiple CSS or JavaScript files, removes unnecessary spaces and comments, makes gzip compression, and sets the browser's cache header. Minify is designed to resemble Yahoo's Combo Handler service, but minify can merge any JavaScript and CSS files you want to merge.

In general, site speed bottlenecks are in the front, and the most critical is the load speed of resources, but most browsers have a single domain number of concurrent requests limit, so if there is a lot of resources in a page, such as CSS and JavaScript files, it will obviously reduce the loading speed of the site, The better way is to access multiple files through a single request, which will not affect the previous file maintenance, but also reduce the clear amount of resources, Minify is born. Here are some of the minify used by Yahoo! Optimization criteria:

1. Make fewer HTTP requests

2. Add an Expires or a cache-control Header

3. Gzip Components

4. Minify JavaScript and CSS

5, Configure Etags

6. Keep Components under 25K

The following two images are a comparison of the site request time before enabling minify and after enabling Minify, and you can see that after enabling Minify, the load time of the resource is reduced from 250ms to 125ms, saving a total of 50% of the time.

Characteristics:

Merging multiple CSS or JavaScript files into one file, reducing the number of requests, and minify processing

Uses multiple open source libraries, including jsmin.php, Minify css,minify HTML

Server-Side Caching (Fils/apc/memcache) to avoid unnecessary duplication of processing

When the browser has a cache of resources, return HTTP 304 not Modified

Automatically generate URIs when multiple files are merged

When server-side caching is turned on, Minify can handle up to hundreds of concurrent requests per second on average servers

Turn on the content-encoding:gzip according to the request header. Minify provides gzipped files faster than Apache's Mod_deflate module in case server-side cache is turned on

Installation

Download the latest minify, then unzip the file to the "Min" folder

Copy the "Min" folder to the document_root of your own website, if you want minify to work in a subdirectory, see here

Use

Assuming the site domain name is http://example.com,Minify installed in the root directory of the virtual host, then visit http://example.com/min/, we will see a "minify URI Builder", We can enter the file URI that needs to be merged, as follows

After clicking Update, the system automatically generates a merged uri:/min/?b=js&f=jquery-a.js,jquery-b.js,jquery-c.js. If you feel that the URI is too long, you can specify group by configuration file, edit the groupsconfig.php file under Min directory, and add the following content:

return Array  Array('//js/jquery-a.js ', '//js/jquery-b.js ', '//js/jquery-c.js '),//);

You can then access it through/MIN/?G=JS.

Minify when the resource is requested for the first time, it will merge, Gzip, remove whitespace, comment and so on, and then cache the processed results, by default the file cache, the cache key starts with Minify_, modifies min/ config.php file, configure the location where the cache files are stored:

$min _cachepath = '/tmp ';

In addition to caching through files, Minify also supports memcache caching, modifying min/index.php files, and adding the following code:

require ' lib/minify/cache/memcache.php '$memcachenew$memcache->connect ( ' localhost ', 11211$min _cachepathnew minify_cache_memcache ($memcache);

Minify supports two debug modes, one is to debug PHP errors by firephp, modify the min/config.php file, and add the following code:

$min _errorlogger true;

The other is to debug the error by adding flag to the URL, adding the min/config.php in the

$min _allowdebugflag true;

Then you can debug it in http://example.com/min/f=jquery-a.js,jquery-b.js,jquery-c.js&debug=1 mode.

Reference:

Http://code.google.com/p/minify/wiki/UserGuide

http://www.mrclay.org/2008/09/19/minify-21-on-mrclayorg/

Article Source: http://weizhifeng.net/2011/04/30/performance-optimization-using-minify/

Use Minify to optimize site performance

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.