Manually gziped js files not working

安稳与你 提交于 2019-12-23 05:38:11

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1038396/manually-gziped-js-files-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!