如何获取apache服务gzip文件?

时间:2018-02-22 04:55:58

标签: php angular apache

前端:角度 后端:PHP 服务器:Apache

  1. 使用webpack插件(bundle.js.gz)压缩文件
  2. 运行但我收到错误。 未捕获的SyntaxError:无效或意外的令牌bundle.js.gz:1

  3. 状态代码为200,标题类似于

    接受编码:gzip,deflate,br

  4. 我想念什么?

1 个答案:

答案 0 :(得分:0)

您要做的是提供预压缩的内容。 (bundle.js.gz) 将以下部分添加到您的site.conf中并重新加载。

<IfModule mod_headers.c>
    # Serve gzip compressed CSS and JS files if they exist
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.(css|js)"         "$1\.$2\.gz" [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped &
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
</IfModule>