【问题标题】:GZIP Compression for all HTML elements所有 HTML 元素的 GZIP 压缩
【发布时间】:2013-11-29 12:13:19
【问题描述】:

我正在尝试在 .htaccess 文件中进行 GZIP 压缩,我已经测试了 HTML 页面,并且由于某种原因它们都被压缩了它不会压缩我的 javascriptscss 文件?

有人知道要在htaccess 文件中添加的代码以确保网站中的所有元素都被压缩吗?

【问题讨论】:

    标签: javascript html css .htaccess gzip


    【解决方案1】:

    您确定还包括 js 和 css 文件扩展名吗?

    <ifModule mod_gzip.c>
      mod_gzip_on Yes
      mod_gzip_dechunk Yes
      # filetypes to cover
      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>
    

    Source

    或者:

    <IfModule mod_deflate.c>
        #The following line is enough for .js and .css
        AddOutputFilter DEFLATE js css
        AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html     
        #The following lines are to avoid bugs with some browsers
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
    </IfModule>
    

    here for further information

    【讨论】:

    • 感谢您的回复,这两种方法我都试过了,它只会压缩 HTML 页面。 CSS 和 JS 文件仍然不压缩
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多