1、使用工具提高网站的访问体验。
使用YSlow、pagespeed等工具找到网站的瓶颈,以及网站可以优化的地方,提高网站的访问效率和访问体验。
2、开启web服务器的gzip压缩,减少网络流量。
web服务器包括IIS,Apache,Nginx等。
应用服务器包括tomcat等。
2.1开启apache-windows的gzip
httpd官网文档
http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
|
1
2
3
4
5
6
7
8
9
10
11
|
1. httpd.conf中打开deflate_Module和headers_Module模块
2. httpd.conf中添加:
<
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 .(?:pdf|doc)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript
</
IfModule
>
|
3、开启浏览器缓存,指定静态资源的有效期。
3.1开启apache-windows的静态文件浏览器缓存
httpd官网文档:
http://httpd.apache.org/docs/2.2/mod/mod_expires.html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
1、在apache的http.conf文件中开启expires_module模块
2、添加下面的配置
<
IfModule
expires_module>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
# expire stylesheets and javascript after 1 week in the website visitor cache
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
# expire flash and XML 1 month and 1 week respectively in the website visitor cache
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/xml "access plus 1 week"
</
IfModule
>
|
4、减少静态资源的重复加载,例如image,js,css文件。
将静态资源单独、统一管理。
单独管理之后就可以实现将静态资源交给web服务器处理,应用服务器只处理动态的请求。
统一管理之后就可以减少静态文件的重复加载,对于相同的资源,都引用相同的地址,统一做管理和更新。
本文转自 virusswb 51CTO博客,原文链接:http://blog.51cto.com/virusswb/1224225,如需转载请自行联系原作者