Website Access Optimization (ii): Enable Apache server gzip compression

Source: Internet
Author: User
Tags deprecated browser cache piwik

yesterday, the bandwidth was upgraded from 1M to 2M, and after using the CDN version of jquery, the website was accessed by an average of 5s (in the case of disallowed caching, using the cache around 2.8s) down to 2.8s.

today, continue to optimize.

1th Step:
The picture is compressed, 70kb above the banner with a large image, compressed into about 50KB. Picture quality slightly reduced a little, no money even high-definition pictures can not afford, so still have to have money, make money.

2nd Step:
JS compression.

Yesterday, also used the online download of the JS/CSS compressor, when deployed, with a compressed version. Speed does not significantly improve, probably because JS and CSS are very few, and are relatively small reasons.

In the evening, with Baidu Webmaster detected the next website visit, average 3s more than my local (Hubei-Wuhan -20MB bandwidth) 2.8s to slow the appearance of 0.7s.

One of the diagnostic recommendations is to use gzip compression.

So, today the focus is on trying Apache to turn on gzip compression.
1th Step:Locate and open the httpd.conf file in the apache/conf directory
2nd step: Open the Deflate_module and Headers_module modules in httpd.conf by removing the following two lines in front of them:

LoadModule Deflate_module modules/mod_deflate.so

LoadModule Headers_module modules/mod_headers.so

3rd Step:Add the following code at the bottom of the httpd.conf file to configure the files that need to be compressed:

<ifmodule deflate_module>
Setoutputfilter DEFLATE
# Don ' t compress images and other
setenvifnocase Request_uri. (?: gif|jpe?g|png) $ no-gzip dont-vary
setenvifnocase Request_uri. (?: Exe|t?gz|zip|bz2|sit|rar) $ no-gzip dont-vary
setenvifnocase Request_uri. (?:p df|doc) $ no-gzip dont-vary
addoutputfilterbytype DEFLATE text/html text/plain text/xml text/css
addoutputfilterbytype DEFLATE Application/x-javascript
</IfModule>
4th step:Restart Apache Server
It is better to check the syntax first, whether it is correct.
/etc/init.d/httpd-t
/ETC/INIT.D/HTTPD restart
5th step: Use the tool to re-detect whether gzip compression is turned on. Considering the relevant ad detection mechanism, the specific gzip detection tool access address can be found in search engines.
http://tool.chinaz.com/Gzips/
Enter your domain name.

Alternatively, you can use Chrome to view it.    

    1. Content-encoding:gzip
    2. After you start gzip compression, Response Headers, there will be a line shown above.

4 Questions:
1.Apache turn on gzip compression, and manual compression js/css How big is the difference?
Effect, of course, is the gzip effect is good.
2.Apache version issue.
Native Apache is 2.4.9, and on-line Apache is 2.2.
Local initial error, the internet searched the next "Addoutputfilterbytype"
Apache Addoutputfilterbytype is deprecated. How to rewrite using Mod_filter?
Online there is a saying that 2.4 no longer support, but later, the 2.2 version has been successful.

Version 2.4 of Addoutputfilterbytypeconfiguration, refer to the following:Http://stackoverflow.com/questions/5230202/apache-addoutputfilterbytype-is-deprecated-how-to-rewrite-using-mod-filter
The native 2.4 Apache did not succeed.

3. In. htaccess, the configuration of gzip compression has not been successful.
4. Statistical procedure Piwik.js has a certain effect on response time.
Piwik is occasionally not stable enough, especially when the bandwidth is 1M.
----------------------------------
On, gzip compression, the home page average access time dropped to 1.8s.
1.82s (LOAD:1.28,DOMCONTENTLOADED:397MS)

When caching is enabled, the 2nd access:
1.00s (load:469ms,domcontentloaded:352ms)
----------------------------------
Bandwidth upgrade to 3M, average access speed:/http

Disable browser cache: 1.69s (load:1.16s,domcontentloaded:415ms)

Start browser cache: 1.18s (load:640ms,domcontentloaded:349ms)

----------------------------------
thinkphp Cache: If it is in debug mode, it will probably cost about 1s more.
----------------------------------
Summary: After upgrading the bandwidth from 1M to 3M, the image is compressed with fireworks, and the Apache gzip compression is turned on, using the CDN version of jquery,
Average access speed from 5s to 1.5s.

Of course, thinkphp uses the cache, and the browser does not disable it in the case of caching.
can open within 2s, everyone can accept it.

Wuhan Nine days Bird technology: http://jiutianniao.comhttp://jiutianniao.com
Welcome everyone, visit the official website to try, response speed.

----------------------------------
Resources:
Http://jingyan.baidu.com/article/db55b609a7bc234ba20a2f7e.html
Http://stackoverflow.com/questions/5230202/apache-addoutputfilterbytype-is-deprecated-how-to-rewrite-using-mod-filter   

Website Access Optimization (ii): Enable Apache server gzip compression

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.