2
我试图压缩所有网站文件以优化网站的性能。到目前为止,我已经包含了来自HTML5 boilerplate .htaccess示例的压缩部分。在JavaScript文件上强制GZIP压缩
下面是相关的代码片段:
# ------------------------------------------------------------------------------
# | Compression |
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
# Force compression for mangled headers.
# http://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>
# Compress all output labeled with one of the following MIME-types
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
# and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
# as `AddOutputFilterByType` is still in the core directives).
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
审查gzipwtf.com似乎将客户的网站被GZIPing所有的CSS文件,但由于某种原因,JavaScript是被忽略了。我对.htaccess
以及这方面的乐趣相当陌生,所以我不确定如何去强制压缩。有什么建议么?
英雄!谢谢,这似乎工作正常。如果你想记录它作为答案,我会给你的荣誉。我还提出了一个HTML5 Boilerplate回购问题,以确保它能够继续向前发展。再次感谢! – Sheixt 2014-09-03 10:08:32