在.htaccess中使用gzip进行压缩

编程入门 行业动态 更新时间:2024-10-19 19:45:12
本文介绍了在.htaccess中使用gzip进行压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Using Gzip for Compression in .htacess to increase page loading speed on www.snapagency

# 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

我尝试过: 我有什么理由不这样做 - 或者人们发现使用插件更容易或更有用吗? wordpress/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? wordpress/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

我尝试过: 我有什么理由不这样做 - 或者人们发现使用插件更容易或更有用吗? wordpress/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? wordpress/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进行压缩

本文发布于:2023-10-31 16:12:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546604.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess   gzip

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!