mattstuehler
mattstuehler

Reputation: 9332

Gzip working for html, but not javascript or css (Apache)

On my site, the html files are gzipped.

However, the javascript, css, and svg files are not.

The server uses Apache/2.2.22.

I'm using the .htaccess file from HTML5boilerplate. Here's the relevant section:

<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" \
                                  "application/javascript" \
                                  "application/json" \
                                  "application/ld+json" \
                                  "application/manifest+json" \
                                  "application/rdf+xml" \
                                  "application/rss+xml" \
                                  "application/schema+json" \
                                  "application/vnd.geo+json" \
                                  "application/vnd.ms-fontobject" \
                                  "application/x-font-ttf" \
                                  "application/x-javascript" \
                                  "application/x-web-app-manifest+json" \
                                  "application/xhtml+xml" \
                                  "application/xml" \
                                  "font/eot" \
                                  "font/opentype" \
                                  "image/bmp" \
                                  "image/svg+xml" \
                                  "image/vnd.microsoft.icon" \
                                  "image/x-icon" \
                                  "text/cache-manifest" \
                                  "text/css" \
                                  "text/html" \
                                  "text/javascript" \
                                  "text/plain" \
                                  "text/vcard" \
                                  "text/vnd.rim.location.xloc" \
                                  "text/vtt" \
                                  "text/x-component" \
                                  "text/x-cross-domain-policy" \
                                  "text/xml"

</IfModule>

For what it's worth - it's not related to subfolders. If I put a file named "test.html" in the main directory - it's gzipped. If I rename it "test.js" - it's not.

[UPDATE]

So, this was dumb.

As I mentioned, I was using the .htaccess file from html5boilerplate.

When I looked at that closely, I noticed these notes:

# (!) For Apache versions below version 2.3.7 you don't need to
# enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
# and `</IfModule>` lines as `AddOutputFilterByType` is still in
# the core directives.

This applies to me, since the server uses Apache/2.2.22.

Sure enough, as soon as I removed <IfModule mod_filter.c> and <IfModule mod_filter.c>, everything worked as it should have (i.e., the javascript, css, and other file types included in that list were all gzipped.

I'll leave this question, just in case anyone else makes the same mistake I did.

Upvotes: 1

Views: 769

Answers (2)

mattstuehler
mattstuehler

Reputation: 9332

So, this was dumb.

As I mentioned, I was using the .htaccess file from html5boilerplate.

When I looked at that closely, I noticed these notes:

# (!) For Apache versions below version 2.3.7 you don't need to
# enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
# and `</IfModule>` lines as `AddOutputFilterByType` is still in
# the core directives.

This applies to me, since the server uses Apache/2.2.22.

Sure enough, as soon as I removed <IfModule mod_filter.c> and <IfModule mod_filter.c>, everything worked as it should have (i.e., the javascript, css, and other file types included in that list were all gzipped.

I'll leave this answer, just in case anyone else makes the same mistake I did.

Upvotes: 1

Brezelfelder
Brezelfelder

Reputation: 61

It looks like you missed something:

AddType image/svg+xml .svg

AddOutputFilterByType DEFLATE image/svg+xml

https://stackoverflow.com/a/21533084/1491007

Best, Ralf

Upvotes: 1

Related Questions