我想在php网站上启用g zip压缩我找到了两种方法来做到这一点更有效率

时间:2016-09-07 11:00:45

标签: php gzip

我有两种方法可以做到这一点,下面哪一种更有效,而且我需要放置。 htaccess或其他地方

方法1:

 summary(bb2[is.na(bb2$time_after_first), ])

      first_order_date      order_date          days_since_first
     Min.   :2015-01-31   Min.   :2015-01-31     Min.   :  0.0   
     1st Qu.:2015-08-31   1st Qu.:2016-02-10     1st Qu.: 52.0   
     Median :2015-11-30   Median :2016-04-08     Median :123.0   
     Mean   :2015-10-27   Mean   :2016-03-25     Mean   :150.2   
     3rd Qu.:2016-01-31   3rd Qu.:2016-05-29     3rd Qu.:211.0   
     Max.   :2016-05-31   Max.   :2016-09-04     Max.   :582.0   

     time_after_first
     <3months   :   0   
     12-15months:   0   
     15-18months:   0   
     18-21months:   0   
     3-6months  :   0   
     (Other)    :   0   
     NA's       :7407   

方法2

# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>

# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 7200 seconds"
  ExpiresByType image/gif "access plus 2678400 seconds"
  ExpiresByType image/jpeg "access plus 2678400 seconds"
  ExpiresByType image/png "access plus 2678400 seconds"
  ExpiresByType text/css "access plus 518400 seconds"
  ExpiresByType text/javascript "access plus 2678400 seconds"
  ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>

# Cache Headers
<ifmodule mod_headers.c>
  # Cache specified files for 31 days
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  # Cache HTML files for a couple hours
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  # Cache PDFs for a day
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  # Cache Javascripts for 31 days
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</ifmodule>

1 个答案:

答案 0 :(得分:0)

启用gzip压缩的最简单方法是在htaccess中添加代码。如果您有权访问服务器根并且知道系统设置,则使用httpd-vhosts.conf文件启用gzip压缩。