手动gzip压缩的js文件不起作用 [英] Manually gziped js files not working

查看:371
本文介绍了手动gzip压缩的js文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道什么可能导致这种情况发生吗?

Does anyone know what might be causing this to happen?

该文件已正确上载,具有正确的权限,并且<script>标记正确指向该文件.

The file is uploaded correctly, it has the right permissions, and the <script> tag points to it correctly.

我在文件上运行的命令是:

The command I ran on the file was:

gzip file.js

那会是什么?

推荐答案

此处有两个概念:文件类型和用于传输的编码. 您必须安排服务器知道Type是application/x-javascript,而Encoding是x-gzip. gzip编码是在每次下载时即时发生还是提前完成一次取决于服务器配置.

There are two concepts here: Type of the file and the Encoding used for transmission. You have to arrange for the server to know that the Type is application/x-javascript and the Encoding is x-gzip. Whether that gzip encoding happens on the fly at every download, or is done once in advance depends on server configuration.

这是一个如何配置Apache以支持预压缩的JS和CSS文件的示例:

Here's an example from of how to configure Apache to support pre-compressed JS and CSS files:

# Compressed javascript files
AddEncoding x-gzip .jgz
AddType application/x-javascript .jgz

# Compressed css files
AddEncoding x-gzip .cgz
AddType text/css .cgz

其他服务器(非Apache)或动态(未预压缩)服务器端压缩的配置会有所不同.

Configuration for other servers (non-Apache) or for dynamic (not pre-compressed) server-side compression will differ.

这篇关于手动gzip压缩的js文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆