Author |
Topic: Simple steps to speed up web page -- server side settings |
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
Simple steps to speed up web page -- server side settings |
1) Take advantage of caching to save the trips for static contents.
Use Expires or Cache-Control:
<IfModule mod_expires.c>
### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif A2592000
### Expire .jpg's 1 month from when they're accessed
ExpiresByType image/jpg "access 1 month"
### Expire everything else 1 day from when it's last modified
ExpiresDefault "modification plus 1 day"
### Apply a Cache-Control header to index.html
<Files index.html>
Header append Cache-Control "max-age=3600, must-revalidate"
</Files>
</IfModule>
Request Header:
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8
Connection keep-alive
Pragma no-cache
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.3
Host www.mycompany.com
User-Agent Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/535.8 (KHTML, like
Gecko) Chrome/17.0.942.0
Safari/535.8
Accept */*
Cache-Control no-cache
Referer http://www.mycompany.com/
Response Header:
Date Thu, 24 Nov 2011 00:05:36 GMT
Connection close
Content-Length 83016
Last-Modified Mon, 19 Sep 2005 05:31:21 GMT
Server Apache/2.2.21 (Amazon)
ETag "22e65-14448-4011940dedc40"
Content-Type image/gif
Accept-Ranges bytes
Cache-Control max-age=2592000
Expires Sat, 24 Dec 2011 00:26:20 GMT
|
|
|
|
|
|
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
Step 2) Use Keep-Alive to avoid excess connections |
Keep-Alive is active only with files where the length is known beforehand. This means that most CGI scripts, server-side included files and directory listings will not use the Keep-Alive protocol.
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15
Request Header:
GET /css/layout.css HTTP/1.1
Connection: Keep-Alive
Response Header:
HTTP/1.1 200 OK
Content-Length: 1408
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
|
|
|
|
|
|
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
Step 3) Enable GZIP compression to speed up your web page |
Compress everything except images
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
Request Header:
GET /css/layout.css HTTP/1.1
Accept-Encoding: gzip, deflate
Response Header:
HTTP/1.1 200 OK
Content-Encoding: gzip
|
|
|
|
|
|
|
EricJ member offline |
|
posts: |
50 |
joined: |
02/22/2007 |
from: |
CA |
|
|
|
|
|
Practical results show that the trick #1 is mazing |
Just applying the trick #1 "Take advantage of caching to save the trips for static contents", most pages of my website are already triple faster. Here is what I put:
<IfModule mod_expires.c>
### activate mod_expires
ExpiresActive On
### Expire ALL IMAGES 1 month from when they're accessed
ExpiresByType image/* A2592000
## Expire .css's 1 month from when they're accessed
ExpiresByType text/css "access 1 month"
### Expire everything else 1 day from when it's last modified
ExpiresDefault "modification plus 1 day"
### Apply a Cache-Control header to index.html
<Files index.html>
Header append Cache-Control "max-age=3600, must-revalidate"
</Files>
</IfModule>
Here is what I got:
+-----------------------------------------------------------------+
| | | Time | Requests | Bytes In |
+-----------------------------------------------------------------+
| Base line | First View | 1.470s | 11 | 130 KB |
|-----------------------------------------------------------------|
| Before trick #1 | Repeat View | 1.001s | 11 | 2 KB |
| After trick #1 | Repeat View | 0.122s | 0 | 0 KB |
+-----------------------------------------------------------------+
Observations: The trips from client to server in order to form the webpage (gif,css,etc) has dropped significantly from 11 to 0. Even though the repeat view trips bring essentially no pay-load but 304 Not Modified, as evidenced by 2 KB, the useless trips still takes decent amount of time to bother the server. The speed says it all by witnessing 1.001s vs. 0.122s.
Conclusion: Trick #1 "Take advantage of caching" is a win-win situation for both user and server: user feels much faster whileas server saves a lot of bandwidth.
|
|
|
|
|
|
|
EricJ member offline |
|
posts: |
50 |
joined: |
02/22/2007 |
from: |
CA |
|
|
|
|
|
Trick #2 KeepAlive benefits the first-time visitors the most |
Here what I put:
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
Here what I got:
+--------------------------------------------------------------------+
| | | Time | Connections | Bytes In |
+--------------------------------------------------------------------+
| Before trick #2 | First View | 1.470s | 11 | 130 KB |
| After trick #2 | First View | 1.263s | 6 | 130 KB |
+--------------------------------------------------------------------+
Observations: The connections used to grab all the components (gif,css,etc) of the first webpage has dropped from 11 to 6; The speed says it all by witnessing 1.263s vs. 1.470s.
Conclusion: While the trick #1 (taking advantage of cache) benefits the users from the repeat views, the trick #2 Keep-Alive benefits the first-time visitors the most. That is also a critical factor for website to gain better user experience for the first-time visitors. Survey reveals that first-time visitors to a new website tends to run away very quickly from it if its first page is too slow to load.
"Your website has about 3 seconds to take a good impression, otherwise 40 percent visitors will just leave. The worst is that they will never come back again."
|
|
|
|
|
|
|
|