国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Apache > 正文

在Apache服務器上啟用GZip壓縮靜態內容的方法

2024-08-27 18:25:42
字體:
來源:轉載
供稿:網友

為了優化網站的訪問速度,我們可以通過對靜態內容進行壓縮,從而減少網頁加載的時間,大大節省用戶的帶寬。在這篇文章中,我將介紹如何使用Apache和.htaccess文件進行靜態內容壓縮。

首先讓我介紹一下,我們可以使用兩種不同的方法壓縮內容:GZip 和 deflate。

介紹

GZip方法在早期的apache版本中使用(在Apache 1.3之前)。但在那之后apache引入了deflate方法,相比GZip并沒有太大的效果(但仍是非常好的)。然而,GZip在apache 1.3之后不再提供更多的支持。因此,你的Apache版本必須大于1.3,如果沒有,你必須升級到最新版本的Apache。

在使用壓縮之前,你必須啟用apache的mod_deflate模塊。要啟用這個模塊,你只需要從httpd.conf文件去掉這個模塊行。

啟用這個模塊后,你的服務器準備好提供壓縮的內容。但是,服務器只有當它接收到來自客戶端的相應頭文件時,才會創建壓縮內容。所以,現在你需要將下面的代碼放置到你網站的htaccess文件,才能通知服務器提供壓縮的內容。

.HTACCESS代碼

<ifmodule mod_deflate.c=""> # force deflate for mangled headers # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ <ifmodule mod_setenvif.c=""> <ifmodule mod_headers.c="">  SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)/s*,?/s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding  RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding </ifmodule> </ifmodule>  # HTML, TXT, CSS, JavaScript, JSON, XML, HTC: <ifmodule filter_module=""> FilterDeclare COMPRESS FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype FilterChain  COMPRESS FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no </ifmodule>  <ifmodule !mod_filter.c=""> # Legacy versions of Apache AddOutputFilterByType DEFLATE text/html text/plain text/css application/json AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/xml application/xml text/x-component AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml  AddOutputFilterByType DEFLATE application/atom+xml AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject  AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype </ifmodule></ifmodule>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙游县| 西吉县| 蒲城县| 乌审旗| 墨竹工卡县| 华池县| 磴口县| 亚东县| 和平区| 延川县| 长武县| 荔波县| 来安县| 抚远县| 临西县| 呼和浩特市| 谷城县| 新郑市| 阿拉善右旗| 定陶县| 黄浦区| 长丰县| 岢岚县| 堆龙德庆县| 博乐市| 河曲县| 甘谷县| 正安县| 鲁甸县| 休宁县| 涟水县| 沁阳市| 南汇区| 长子县| 阆中市| 曲靖市| 夏津县| 丰台区| 尉氏县| 三门峡市| 吴桥县|