外贸B2C系列: magento性能优化系列一:.htaccess调整及其他

 magento性能优化系列一:.htaccess调整及其他

转自:http://blog.csdn.net/shangxiaoxue/article/details/7607965

本文主要讲解magento性能优化的几个方面。如果不加注明的话,基本上适用任一版本。

调整 .htaccess

默认的 .htaccess是包含有关于处理性能的部分的,但是是被注释掉的,可以选择合适的部分取消注释;

启用输出压缩

这一部分会打开 apache 的mod_deflate模块,将text、 css 和 javascript 先进行压缩再发送到浏览器。这样就会减少网络下载量,缩短等待时间,示例如下:

  1. <IfModule mod_deflate.c> 
  2.  
  3. ############################################ 
  4. ## enable apache served files compression 
  5. ## http://developer.yahoo.com/performance/rules.html#gzip 
  6.  
  7.     # Insert filter on all content 
  8.     SetOutputFilter DEFLATE 
  9.     # Insert filter on selected content types only 
  10.     AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript  
  11.  
  12.     # Netscape 4.x has some problems... 
  13.     BrowserMatch ^Mozilla/4 gzip-only-text/html 
  14.  
  15.     # Netscape 4.06-4.08 have some more problems 
  16.     BrowserMatch ^Mozilla/4\.0[678] no-gzip 
  17.  
  18.     # MSIE masquerades as Netscape, but it is fine 
  19.     BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
  20.  
  21.     # Don't compress images 
  22.     SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary 
  23.  
  24.     # Make sure proxies don't deliver the wrong content 
  25.     Header append Vary User-Agent env=!dont-vary 
  26.  
  27. </IfModule> 
<IfModule mod_deflate.c>

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter on all content
    SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript 

    # 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

    # 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

</IfModule>

启用Expires Headers

注意:这一配置在Litespeed servers无效
浏览器使用 Expires Headers来确定页面组件可以被缓存多长时间。静态的部件,如图像,可以设置为永不过期,但还是建议设置一个Expires Headers。要打开这个特性,可以取消注释对应的行并添加"ExpiresActive On" 如下所示:

  1. <IfModule mod_expires.c> 
  2.  
  3. ############################################ 
  4. ## Add default Expires header 
  5. ## http://developer.yahoo.com/performance/rules.html#expires 
  6.  
  7.     ExpiresActive On 
  8.     ExpiresDefault "access plus 1 year" 
  9.  
  10. </IfModule> 
<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On
    ExpiresDefault "access plus 1 year"

</IfModule>


 

禁用 ETags
ETags(Entity tags)是服务器和浏览器的一个功能,它用来判断浏览器缓存里的元素是否和原来服务器上的一致。ETags比last-modified date更具有弹性,它用一个独一无二的字符串来标识一个元素的版本。 要关闭它很简单,做法如下:

  1. ############################################ 
  2. ## If running in cluster environment, uncomment this 
  3. ## http://developer.yahoo.com/performance/rules.html#etags 
  4.  
  5.     FileETag none 
############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags

    FileETag none


Magento 后台设置及调整

有几个功能,可以在 Magento 的后台启用他们。
合并CSS 和JS 文件

合并之后,能有效减少http请求数量,1.4.x或之前的版本,可以使用Fooman_Speedster 扩展替代此设置。
  1:  登入后台 System > Configuration > Developer.
  2:  "Javascript Settings", 设置 "Merge Javascript Files" 为 YES.
  3: 在"CSS Settings", 设置"Merge CSS Files" 为 YES.
  4: Clear the cache.

启用 Magento 编译特性

magento程序文件存放在如下目录

  1. app/code/local 
  2. app/code/community 
  3. app/code/core 
  4. lib 
    app/code/local
    app/code/community
    app/code/core
    lib


每次加载页面时,都需要搜索这些文件,并读取对应文件;Mage_Compiler 能有效减少对这些文件的重复搜索和读取,因为它将所有的application文件都copy到一个单一的目录里,并且会缓存常用的页面。
    1:登入后台 System > Tools > Compilation.
    2:Click "Run Compilation Process"

其他调整

使用并行下载;大多数浏览器都会限制对域最大连接数位4。如果您的页面有很多来自相同的域中的组件,这会导致花费较长的时间加载页面。但是你可以将一些静态内容映射到不同的子域上,从而欺骗浏览器同时运行更多个进程。
1:在服务器上创建 Pointer domains . 如 "static.example.com",  "js.example.com", "media.example.com", "skin.example.com" 。
2.改变 media, js, 和skin URLs 在Magento后台,如图所示:

3:编辑Vhost file使apache不要尝试加载子目录../media, ../skin, or ../js,而是加载根目录,示例如下:

  # subdomain logic
  RewriteEngine On
  RewriteOptions inherit
  RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
  RewriteCond %{HTTP_HOST} !^example\.com [NC]

Add:

  RewriteCond %{HTTP_HOST} !^js\.example\.com [NC]
  RewriteCond %{HTTP_HOST} !^media\.example\.com [NC]
  RewriteCond %{HTTP_HOST} !^skin\.example\.com [NC]

4:Save the file and restart Apache.
5:Clear the cache and reload the page 并确保静态内容是来自于新的URLs.

6:Clean cache

清除DB相关log

magento性能优化系列二:db篇

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值