gpt4 book ai didi

javascript - 强制对 JavaScript 文件进行 GZIP 压缩

转载 作者:行者123 更新时间:2023-11-29 19:34:50 25 4
gpt4 key购买 nike

我正在尝试压缩所有网站文件以优化网站性能。到目前为止,我已经包含了 HTML5 boilerplate .htaccess 中的压缩部分。例子。

这是相关的代码片段:

# ------------------------------------------------------------------------------
# | 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 后,客户网站似乎对所有 CSS 文件进行了 GZIP 压缩,但由于某种原因,JavaScript 被忽略了。我对 .htaccess 的乐趣和这方面的事情还很陌生,所以我不确定如何进行强制压缩。有什么建议吗?

最佳答案

为确保正确的互操作性,您需要为 JavaScript 指定两种 MIME 类型:

application/javascript
text/javascript

还有一个,不过只在过渡期用过:

application/x-javascript

关于javascript - 强制对 JavaScript 文件进行 GZIP 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25641486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com