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

来源:互联网 发布:淘宝付款方式设置在哪 编辑:程序博客网 时间:2024/05/24 06:09

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

调整 .htaccess

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

启用输出压缩

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

<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    # enable resulting html compression    php_flag zlib.output_compression on </IfModule>

启用Expires Headers

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

<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更具有弹性,它用一个独一无二的字符串来标识一个元素的版本。 要关闭它很简单,做法如下:

############################################## 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程序文件存放在如下目录

    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篇


本文链接地址:http://blog.csdn.net/shangxiaoxue/article/details/7607965


原创粉丝点击