给你的Magento提个速吧

2,023 人次阅读
一条评论

共计 2042 个字符,预计需要花费 6 分钟才能阅读完成。

Magento的缺点就是速度太慢,特别是当你使用Magento的默认配置时。当然,有一些方法是可以为Magento提速的,现在我们就便开始吧!

第一步,编辑.htaccess文件

开启输出压缩模式

打开APACHE的mod_deflate模块,Apache会在发送给浏览器前自动压缩text, css, and javascript ,一次减小下载的文件大小。要想开启这个功能,可以参考下面的文档,取消相应行的注释即可:

############################################
## 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

开启过期报文头Expires Headers

浏览器会根据Expires headers来决定一篇文章可以缓存多久。静态文件,可以缓存很长时间,但是,你懂的,所有文件都应该有一个过期时间。开启这个功能,只需取消相应行注释,在其上面一行添加 “ExpiresActive On” 字段,如下:

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
 
    ExpiresActive On
    ExpiresDefault "access plus 1 year"

记住,如果你使用长期报头,如果文件发生更改,那么你必须文件的文件名。更多信息参见: http://developer.yahoo.com/performance/rules.html

取消ETags

ETags是浏览器用来判断浏览器缓存里的元素是否和原来服务器上的一致. 这回严重拖慢服务器的速度,特别是当服务器没有正确配置。最好把这个功能关掉吧。关闭方法如下:

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

然后进入Magento后台,确认开启了合并JS和CSS文件功能。

  • Magento admin -> System Configuration -> Developer -> 在“Javascript Settings”选项下,更改“Merge Javascript Files” 为 YES.
  • Magento admin -> System Configuration -> Developer -> 在“CSS Settings”选项下, 更改“Merge CSS Files”为YES

清除缓存.

如果有条件的话,使用CDN吧,但是请注意,何必ingCSS/JS后,如果CDN没有及时正确更新,CSS/JS有可能会使你的页面混乱哦。

开启扁平目录Flat Catalog

Magento使用 EAV模块功能来存储用户和产品数据,使得这些项可以有相当惊人的扩展性,但是也会导致更大的SQL查询。 可以开启Flat Catalog将目录和产品信息合并到一个表,以此提升Magento性能。一般来说,所有的商店都应该开启这个功能。

更多信息参考 http://yslow.org/user-guide/

正文完
 0
评论(一条评论)