Apparently, the file was served from the browser's cache, I did not see the 304 status response in the Firebug window. After emptying the cache, the js file was indeed returned with the application/javascript content type and was gzipped.
Apache AddType directive for .js files does not work
-
03-06-2022 - |
Question
I run YSlow in a couple of sites of mine and it reports that one .js file is not compressed. mod_deflate
is enabled of course (other html and text files are compressed):
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/javascript application/ecmascript text/javascript text/x-javascript
DeflateCompressionLevel 6
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
I used Firebug to see the html headers sent by Apache when directly requesting this .js file and it seems that Apache does not send any Content-type header directive. I suppose this is the reason it does not go through the deflate filter for compression. Then, I added
AddType application/javascript .js
in the corresponding config file in Apache, restarted it and it still does not work. No Content-Type header is sent when requesting the file.
Apache runs in Linux, with PHP enabled (if this helps). mod_mime
module is also enabled.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow