手动 gziped js 文件不起作用

发布于 2024-07-24 22:28:48 字数 178 浏览 4 评论 0原文

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

文件已正确上传,具有正确的权限,并且

我对该文件运行的命令是:

gzip file.js

它可能是什么?

Does anyone know what might be causing this to happen?

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

What could it be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄风 2024-07-31 22:28:48

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

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

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

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

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

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.

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

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

情绪失控 2024-07-31 22:28:48

您只是想使用 javascript 文件吗? 尝试将浏览器指向它,它可能看起来很乱码。 GZIP 用于文件级压缩,而不是压缩 JavaScript。

Are you just trying to use the javascript file? Try pointing your browser at it, it may look quite garbled. GZIP is for file level compression not minifing javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文