Apache 2.4 gzip压缩不适用于JS,但适用于CSS

时间:2014-10-06 14:40:37

标签: apache .htaccess gzip mod-deflate

Apache 2.4使用mod_deflate压缩CSS而不是JS

的.htaccess

# Proper MIME types for all files
<IfModule mod_mime.c>
    AddType application/javascript  js
    AddType text/css                css
</IfModule>

<IfModule mod_deflate.c>
    <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>

    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/javascript text/css               
    </IfModule>
</IfModule>

site.com/src/css/core.css的回复是正确的(编码:30.38 KiB /解码:146.31 KiB)

Status: HTTP/1.1 200 OK
Connection: close   
Expires:    Tue, 06 Oct 2015 14:55:59 GMT   
Date:   Mon, 06 Oct 2014 14:55:59 GMT   
Content-Type:   text/css; charset=utf-8 
Server: Apache  
Accept-Ranges:  bytes   
Last-Modified:  Mon, 06 Oct 2014 13:13:31 GMT   
Vary:   Accept-Encoding 
Cache-Control:  max-age=31536000    
Transfer-Encoding:  chunked 
Content-Encoding:   gzip    
Vary:   Accept-Encoding

site.com/src/js/core.js的回复是KO

Status: HTTP/1.1 200 OK
Connection: close   
Content-Length: 236437  
Expires:    Tue, 06 Oct 2015 14:57:50 GMT   
Date:   Mon, 06 Oct 2014 14:57:50 GMT   
Content-Type:   application/javascript; charset=utf-8   
Server: Apache  
Accept-Ranges:  bytes   
Last-Modified:  Mon, 06 Oct 2014 12:49:48 GMT   
Vary:   Accept-Encoding 
Cache-Control:  max-age=31536000

http.conf (活动模块)

LoadModule access_compat_module modules/mod_access_compat.so
LoadModule alias_module modules/mod_alias.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule cache_disk_module modules/mod_cache_disk.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so

为什么,apache 2.4不压缩JS,而是压缩CSS ??

1 个答案:

答案 0 :(得分:1)

一切看起来都正确......

我记得我在Forefront TMG代理防火墙上遇到了同样的问题,默认情况下,它没有在Content-Encoding类型的请求中传递application/javascript标头。

检查防火墙是否有...