Jac*_*lly 14 html php .htaccess gzip web
我一直在创建一个网站并通过gtmetrix.com检查它的速度.我使用以下.htaccess文件来压缩.js, .css更多文件.
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
Options Indexes
IndexOptions FancyIndexing
ExpiresActive On
ExpiresDefault "access plus 7 days"
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/javascript A2592000
ExpiresByType text/html A2592000
ExpiresByType text/xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/plain A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/bmp A2592000
ExpiresByType application/x-shockwave-flash A2592000
<FilesMatch "\.(html?|txt)$">
ForceType 'text/html; charset=UTF-8'
</FilesMatch>
<FilesMatch "\.(css)$">
ForceType 'text/css; charset=UTF-8'
</FilesMatch>
<FilesMatch "\.(js)$">
ForceType 'text/javascript; charset=UTF-8'
</FilesMatch>
<FilesMatch "\.(css|js)$">
Header append Vary Accept-Encoding
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
但是当我运行页面测试时,它会显示以下内容-----
Compressing the following resources with gzip could reduce their transfer size by 882B (48% reduction).
Compressing http://wooflux.co.cc/ could save 645B (48% reduction).
Compressing http://wooflux.co.cc/style.css could save 237B (51% reduction).
Run Code Online (Sandbox Code Playgroud)
但我已经gzip对我的.htaccess文件进行了压缩.我不知道这里出了什么问题,顺便说一句,我对这种编码风格很陌生.如果我有任何错误,请告诉我.
Mar*_*ter 31
我没有使用mod_gzip,但这里是我的.htaccess我用gzip .js,.css和其他文件通过mod_deflate:
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript
</ifmodule>
#End Gzip
Run Code Online (Sandbox Code Playgroud)
如果您还没有意识到这一点,Firebug对于检查下载的内容是否被gzip压缩是非常有用的.单击Firebug中的"Net"选项卡,然后执行shift-f5以使Firefox重新加载所有.js和.css文件,以便它们显示在Net面板中.单击.js或.css文件旁边的"+",然后单击"标题"选项卡.如果响应是gzip压缩,您将在Response Headers部分中看到"Content-Encoding gzip".我想象IE,Safari和Chrome等价物提供相同的能力.
关于IE6上的gzipping .js和.css文件有一点需要注意.我认为它仅适用于IE6 SP1用户.
| 归档时间: |
|
| 查看次数: |
28423 次 |
| 最近记录: |