【问题标题】:how to gzip or compress a .json file and use it in the frontend .js如何 gzip 或压缩 .json 文件并在前端 .js 中使用它
【发布时间】:2018-08-08 09:28:12
【问题描述】:

我有很大的 json 文件,我在 index.js 中加载页面加载 (javascript) 文件,这会导致加载页面的时间增加。

我应该使用什么来减少这种情况以使页面加载更快?

【问题讨论】:

  • 我已经添加了这个,但它仍然无法正常工作

标签: javascript json apache tomcat gzip


【解决方案1】:

您需要在服务器级别启用 gzip,在配置 compressableMimeType 中您可以指定要压缩的数据类型。

  <Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444"
compression="on" compressableMimeType="text/html,
text/xml,text/plain,text/javascript,text/css,application/json" />

您可以访问http://viralpatel.net/blogs/enable-gzip-compression-in-tomcat/了解配置步骤

【讨论】:

  • 这个 gzip 可以与 $.getJSON 一起使用来访问内容吗?
【解决方案2】:

在您的 Apache 配置中,设置 mod_deflate 参数。 See here for complete doc

根据您的配置,可以定位 apache 配置:

Windows C:\Program Files\Apache Group\Apache2\conf\httpd.conf Linux:/etc/httpd/conf/httpd.conf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 2018-05-06
    • 2011-07-28
    • 1970-01-01
    • 2012-09-15
    相关资源
    最近更新 更多