Im currently trying to activate the gzip compression on a Wordpress website. But the json output of the wordpress embed api doesn't seem to be affected by my htaccess settings.
Here they are:
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/json
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
Does anyone has a clue where my mistake is? Thanks!
Im currently trying to activate the gzip compression on a Wordpress website. But the json output of the wordpress embed api doesn't seem to be affected by my htaccess settings.
Here they are:
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/json
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
Does anyone has a clue where my mistake is? Thanks!
Share Improve this question asked Apr 19, 2018 at 11:14 ChrisRpunktpunktpunktChrisRpunktpunktpunkt 311 silver badge4 bronze badges 2- Still haven't fount the answer. :/ Here a Link to the Json of my site: mein-ruhrgebiet.blog/wp-json/wp/v2/posts/?_embed And here a link to a compressed json site: yelpblog/wp-json/wp/v2/posts/?_embed – ChrisRpunktpunktpunkt Commented Apr 25, 2018 at 5:06
- Did you manage to get it to work? I see your website's JSON is gzipped now. Can't get my setup to work on Ubuntu 20.04, latest apache & php. – workwise Commented Jul 16, 2021 at 7:36
1 Answer
Reset to default 1I used your exact set of .htaccess directives to achive json gzip'ing. Took my files from 23k to 4k.
So I would assume its one of the two following things:
- Your.htaccess is not allowed to use these directives so it ignores them. Thus you either need to do one of the following: a) edit the httpd.conf or /etc/apache/sites-available/site.conf or httpd-vhosts.conf (depending on the system you are on) and add the gzip stuff there. b) edit the same files and give your.htaccess the rights to override these settings. c) check your are really running apache so .htaccess works ;D
- Check that mod_deflate is loaded and if not, enable it. Again this might not be working as you are not running apache or the directives in the htttpd.conf (or wherever) do not cover application/json
If you do have .conf access to make these changes then put the deflate rules in there rather than in the .htaccess, that way the server learns about it at setup time, and not on every file access. increases speed (slightly).
If you do not have .conf access, you need to speak to the server people or hosting company and get them to add the AddOutputFilterByType DEFLATE application/json
for your website, perhaps consider all of the settings you have done above.
As a bonus, if you really want uber small, Brotli compression was specifically made to make fonts smaller, and works on all file types. If you work with a host, ask them if this is possible also as well as gzip, so you have backwards compatibility.