5 August 2014

Compress site using mod_deflate to reduce bandwidth and loading time, also Google Speed suggests it. List of compressible mime-types to compress. You should not compress mime types that compress badly. Compressing images would not result in a lot of gain, but will use a lot of cpu. You can copy this snippet to .htaccess. This only work when you have mod_deflate enabled in Apache. You can use this code in Apache configuration or .htaccess to make this work globally. You can test your site via whatsmyip.org/http-compression-test.

Source code viewer
  1. LoadModule deflate_module modules/mod_deflate.so
  2.  
  3. <IfModule mod_deflate.c>
  4. # Compress HTML, CSS, JavaScript, Text, XML and fonts
  5. AddOutputFilterByType DEFLATE application/javascript
  6. AddOutputFilterByType DEFLATE application/rss+xml
  7. AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  8. AddOutputFilterByType DEFLATE application/x-font
  9. AddOutputFilterByType DEFLATE application/x-font-opentype
  10. AddOutputFilterByType DEFLATE application/x-font-otf
  11. AddOutputFilterByType DEFLATE application/x-font-truetype
  12. AddOutputFilterByType DEFLATE application/x-font-ttf
  13. AddOutputFilterByType DEFLATE application/x-javascript
  14. AddOutputFilterByType DEFLATE application/xhtml+xml
  15. AddOutputFilterByType DEFLATE application/xml
  16. AddOutputFilterByType DEFLATE font/opentype
  17. AddOutputFilterByType DEFLATE font/otf
  18. AddOutputFilterByType DEFLATE font/ttf
  19. AddOutputFilterByType DEFLATE image/svg+xml
  20. AddOutputFilterByType DEFLATE image/x-icon
  21. AddOutputFilterByType DEFLATE text/css
  22. AddOutputFilterByType DEFLATE text/html
  23. AddOutputFilterByType DEFLATE text/javascript
  24. AddOutputFilterByType DEFLATE text/plain
  25. AddOutputFilterByType DEFLATE text/xml
  26.  
  27. # Remove browser bugs (only needed for really old browsers)
  28. BrowserMatch ^Mozilla/4 gzip-only-text/html
  29. BrowserMatch ^Mozilla/4\.0[678] no-gzip
  30. BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  31. Header append Vary User-Agent
  32. </IfModule>
Programming Language: Apache configuration