可选地提供静态压缩的CSS&JS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了可选地提供静态压缩的CSS&JS相关的知识,希望对你有一定的参考价值。

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.
  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>

以上是关于可选地提供静态压缩的CSS&JS的主要内容,如果未能解决你的问题,请参考以下文章