I managed to solve it. The key was to use content negotiation and not rewrite rules.
Here is the uber optimized Mendix Apache config file, it has the following features:
This results in a typical reduction from about 1,400 KB to around 308 KB!!
Here is the file. (Please let me know if you have a better/shorter way of doing this.) The only known issue is that /file requests do not seem to get the file. I will look into this...
<VirtualHost *:80>
ServerName hjonck.local
ErrorLog /var/log/apache2/hjonck-error.log
CustomLog /var/log/apache2/hjonck-access.log common
DocumentRoot "/Users/hjonck/Development/DA/ApacheHosted/deployment/web"
Options +FollowSymlinks -MultiViews
<Location />
order allow,deny
allow from all
</Location>
<LocationMatch "^/mxclientsystem">
order allow,deny
allow from all
Options +MultiViews
AddEncoding gzip .js.gz
AddType text/javascript .js.gz
AddEncoding gzip .css.gz
AddType text/css .css.gz
AddEncoding gzip .html.gz
AddType text/html .html.gz
</LocationMatch>
<LocationMatch "^/forms">
order allow,deny
allow from all
Options +MultiViews
AddEncoding gzip .mxf.gz
AddType application/xml .mxf.gz
AcceptPathInfo On
</LocationMatch>
ProxyRequests Off
ProxyVia on
RewriteEngine on
RewriteLog "/var/log/apache2/hjonck-rewrite.log"
RewriteLogLevel 5
# The main Mendix reverse proxy rule for /xas /file /ws - everything is passed that does not have something on file system
RewriteCond /Users/hjonck/Development/DA/ApacheHosted/deployment/web%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*) http://10.211.55.18:8380/$1 [QSA,P,R,L]
ProxyPassReverse / http://10.211.55.18:8380/
# Deflate setup
SetOutputFilter DEFLATE
AcceptPathInfo On
DeflateCompressionLevel 9
DeflateFilterNote ratio
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Explicit mime types
AddType application/javascript *.js
AddType text/css *.css
AddType application/xml *.mxf
# Add all the types we want compressed
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript
AddOutputFilterByType DEFLATE text/*
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
#Header append Vary User-Agent
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r",%b,%{outstream}n/%{instream}n,%{ratio}n%%' deflate
CustomLog /var/log/apache2/hjonck-deflate.log deflate
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</virtualhost>
When using the nginx web server, you can do:
gzip on;
# will gzip json responses (from /xas/) on the fly
gzip_proxied any;
gzip_types application/json;
# Boo!
gzip_disable "msie6";
# will automagically present the .gz files
gzip_static on;
;-)