问题
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