在.htaccess中使用gzip进行压缩 [英] Using gzip for compression in .htaccess

查看:54
本文介绍了在.htaccess中使用gzip进行压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.htacess中使用Gzip进行压缩以提高https://www.snapagency.com上的页面加载速度



Using Gzip for Compression in .htacess to increase page loading speed on https://www.snapagency.com

# BEGIN GZIP COMPRESSION
<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>
# END GZIP COMPRESSION

# BEGIN DEFLATE COMPRESSION
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
# END DEFLATE COMPRESSION





我尝试过:



我有什么理由不这样做 - 或者人们发现使用插件更容易或更有用吗?



https://wordpress.org/plugins/gzip-ninja-speed-compression/



任何缺点或缺点?



What I have tried:

Is there any reason why I wouldn't do this - or do people find it easier or more useful to use a plugin instead?

https://wordpress.org/plugins/gzip-ninja-speed-compression/

Any cons or drawbacks to either?

推荐答案

mod_gzip_item_include handler ^ cgi-script
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>
#END GZIP COMPRESSION

#BEGIN DEFLATE COMPRESSION
< IfModule mod_filter.c>
AddOutputFilterByType DEFLATEapplication / atom + xml\
application / javascript\
application / json\
application / ld + json\
application / manifest + json\
application / rdf + xml\
application / rss + xml\
application / schema + json \
application / vnd.geo + json\
application / vnd.ms-fontobject\
application / x-font-ttf\
application / x-javascript\
application / x-web-app-manifest + json\
application / xhtml + xml\
application / xml \
font / eot\
font / opentype\
image / bmp\
image / svg + xml\
image / vnd.microsoft.icon\
image / x-icon\
text / cache-manifest\
text / css\\ \\
text / html\
text / javascript\
text / plain\
text / vcard\
text / vnd.rim.location.xloc\
text / vtt\
text / x-compo nent\
text / x-cross-domain-policy\
text / xml
< / IfModule>
#END DEFLATE COMPRESSION
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> # END GZIP COMPRESSION # BEGIN DEFLATE COMPRESSION <IfModule mod_filter.c> AddOutputFilterByType DEFLATE "application/atom+xml" \ "application/javascript" \ "application/json" \ "application/ld+json" \ "application/manifest+json" \ "application/rdf+xml" \ "application/rss+xml" \ "application/schema+json" \ "application/vnd.geo+json" \ "application/vnd.ms-fontobject" \ "application/x-font-ttf" \ "application/x-javascript" \ "application/x-web-app-manifest+json" \ "application/xhtml+xml" \ "application/xml" \ "font/eot" \ "font/opentype" \ "image/bmp" \ "image/svg+xml" \ "image/vnd.microsoft.icon" \ "image/x-icon" \ "text/cache-manifest" \ "text/css" \ "text/html" \ "text/javascript" \ "text/plain" \ "text/vcard" \ "text/vnd.rim.location.xloc" \ "text/vtt" \ "text/x-component" \ "text/x-cross-domain-policy" \ "text/xml" </IfModule> # END DEFLATE COMPRESSION





我尝试过:



我有什么理由不这样做 - 或者人们发现使用插件更容易或更有用吗?



https://wordpress.org/plugins/gzip-ninja-speed-compression/



任何缺点或缺点?



What I have tried:

Is there any reason why I wouldn't do this - or do people find it easier or more useful to use a plugin instead?

https://wordpress.org/plugins/gzip-ninja-speed-compression/

Any cons or drawbacks to either?


如果您使用的是Wordpress平台,那么您可以使用插件。因为大多数使用其他功能,如缓存,cdn服务以及gzip。如果您的网站是定制的,那么您可以使用上面的代码。



我建议您使用NGINX或Litespeed来提供更好的内容。
If you are using Wordpress platform, then you can go for plugins. Because most of it use other features like cache, cdn services along with gzip. If your site is custom made, then you can go for the above code.

I recommend you to use NGINX or Litespeed for better content delivery.


这篇关于在.htaccess中使用gzip进行压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆