Apache2 won't Gzip my js/css - apache

My server doesn't seem to gzip my css and javascript files. It works for HTML.
Here's my config: http://pastie.org/1105941
And here's my result: http://i35.tinypic.com/audv0k.jpg
Also tested Google Page Speed, and made Apache2 log the compression results. They say the same.
What could be wrong here, since it does compress the HTML?

As far as I can see, it is working ... using firefox and the webdeveloper plugin the response for both css and js reports gzip

Download a CSS file with a browers and check the content type. Chances are that it's application/binary or something. If that is the case, you must tell the server that *.css should be sent as text/css, etc:
AddType text/css .css

Related

Apache Server not serving SVGs

What settings do I need to set in order to make Apache serve SVGs?
What I found:
These questions document the use of .htaccess to serve the SVGs with the correct MIME type "image/svg+xml" SVG images not displaying on certain web servers / https://mid.as/kb/00134/configuring-server-to-handle-svg-images / https://davidwalsh.name/serve-svg-image
This question handles the Requested URL not found
None of these helped resolve this issue.
Files:
.htaccess:
AllowOverride All
RewriteEngine on
AddType image/svg+xml svg
Folder structure:
Result:
Other:
Different files like .png work. I also tested it with Node (npx http-server) which worked.
AFAICR any recent version of Apache should have the SVG MIME type already configured. You shouldn't have to do it yourself unless you are running a very old version.
Anyway, a misconfigured MIME type wouldn't casue a 404. I think something else must be going on.
If you haven't already, try looking at the Network tab in your browser dev tools, and the Apache access log to check whether you are actually fetching the URL you think you are. And check that the file permissions are set correctly. Does the file have the correct owner, group, and permissions to be accessed by apache?

What configuration is responsible for a working deflate / gzip?

I had a look in my (standard configurated) httpd.conf on my Apache 2.2 webserver and I was not able to identify what configuration is responsibly that gzip compression is working fine?
I searched for keywords like DEFLATE, AddOutputFilterByType or mod_deflate. But none of these keywords are in my httpd.conf.
Can anyone tell me, why compression works fine with the standard configuration? What configuration line is responsible for that?
You're looking for exactly the right thing, but you're probably not looking in all of your configuration files. You're probably using a multi-file layout, or looking in the complete wrong file.
Try looking for Include, or load mod_info to review the config that way in merged form.
I found the solution: A mod_deflate code in my .htaccess file in a subdirectory on my WordPress blog (Plugin WPSuperCache and Autoptimize) were responsible for the working gzip compression.

Serving gzip content from on Amazon S3 - doesn't work with my application

I've gziped my JavaScript file using gzip and uploaded it to Amazon S3. I've set the following:
content-type: application/x-javascript
content-encoding: gzip
The file was given public permissions.
The problem that when I refer the script to the location (correct one, I've checked) of the gzipped file (with js.gzip at the end), the application doesn't run it. When I tried to view the file in Chrome browser, it tried to download the file instead of showing it.
What I'm doing wrong?
According to one answer of a similar question, there's a bug in Safari (probably Webkit) which stops proper gzip acceptance with the "wrong" file extension.
File extension shouldn't matter, but apparently Webkit screws it up. try either .jgz or .gz.js.
Try to remove:
content-type: application/x-javascript
and only use:
content-encoding: gzip
in your S3 bucket file.js file (gziped, replace .js.gz for .js only).
Now the browser request should work without any problem.

How can I make my server use gzip compression?

I'd like to make my server apply gzip compression to html, php, javascript and css files.
I think I can do it by editing the .htaccess file. Can someone give me the exact code that I would have to add?
Also, if I add the appropriate code to an .htaccess file in the parent directory, does it automatically apply to all sub-directories too? For instance, if I have http://domain1.com pointed at my root directory and http://domain2.com pointed at a sub-directory, will the second domain provide compressed files without me needing to edit the .htaccess file in that directory too?
Thanks
Use mod_deflate
More info here: http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
From the document that Peter Hall referenced on mod_deflate:
AddOutputFilterByType DEFLATE text/html text/css text/plain text/javascript application/javascript
And I believe that the answer is "yes" about the setting propagating down the directory tree to subdirectories. The best thing to do is check the response headers from the site (using FireBug or similar tool where you can watch the network traffic) and verify that the contents are compressed.

how to change mime types in MAMP

I'm developing a website that has a HTML5 video. It looks like when ogg files are served with other mime types than video/ogg firefox flips. I've updated the mime.types file inside the mamp/apache/config folder and have restarted the MAMP server multiple times, but ogg files are still served with plain/text context-type.
Can someone point out what I need to do?
UPDATE
The only time I'm able to change the mime type is if I change the DefaultType text/plain to DefaultType video/ogg which is stupid.
The mime.types file is in Applications/MAMP/conf/apache
There you can alter your mime types.
Reset server after changing the file for it to take effect.
Do you have mod_mime_magic installed and enabled? Is your mime magic working correctly? When you do file -m on one of your OGG files, does it say it is a plain text file? Are the file extensions correct?
Adding mime-type is the same for all, it's just you need to understand how the types will be applied and what's the mime-type point is. In this answer I'll how I tried to add WebAssembly mime-type application/wasm in MAMP.
Here it goes:
I recently tried WebAssembly in MAMP and configured out the below mime-type that works for me.
First, we need to navigate the folder of MAMP in MacOS's Applications/MAMP/conf/apache, And then open the file mime.types in any editor.
After opening the file, add the following line anywhere in the mime.types file:
application/wasm wasm
Here is the example wasm mime type in my mime.types file:
#application/wasm
application/wasm wasm
In MAMP Pro these days you can add <VirtualHost> parameters using the gui. Here's a screenshot showing how I add MIME types for .mjs and .wasm as:
AddType application/javascript .mjs
AddType application/wasm wasm
screenshot
Don't forget to restart the server after adding.