Optionally Serve Statically Compressed CSS & JS


/ Published in: Apache
Save to your folder(s)

Combine this with the my compression script and things load real fast. I think I pulled some of this code of a site on google... can't claim complete credit.


Copy this code and paste it in your HTML
  1. # no weird non-ASCII quotes! Arg! They wasted an hour of time!
  2. # info: http://www.bluehostforum.com/showthread.php?t=11402
  3.  
  4. Options +followsymlinks
  5.  
  6. <FilesMatch "\.js.gz$">
  7. ForceType text/javascript
  8. Header set Content-Encoding: gzip
  9. </FilesMatch>
  10. <FilesMatch "\.js$">
  11. RewriteEngine On
  12. RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  13. RewriteCond %{HTTP:Accept-Encoding} gzip
  14. RewriteCond %{REQUEST_FILENAME}.gz -f
  15. RewriteRule (.*)\.js$ $1\.js.gz [L]
  16. ForceType text/javascript
  17. </FilesMatch>
  18.  
  19. <FilesMatch "\.css.gz$">
  20. ForceType text/css
  21. Header set Content-Encoding: gzip
  22. </FilesMatch>
  23. <FilesMatch "\.css$">
  24. RewriteEngine On
  25. RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  26. RewriteCond %{HTTP:Accept-Encoding} gzip
  27. RewriteCond %{REQUEST_FILENAME}.gz -f
  28. RewriteRule (.*)\.css$ $1.css.gz [L]
  29. ForceType text/css
  30. </FilesMatch>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.