RafaelDeJongh

Performance HTACCESS

Aug 7th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. ### Begin Caching Performance ###
  2. # Use UTF-8 encoding for anything served text/plain or text/html
  3. AddDefaultCharset UTF-8
  4. # Force UTF-8 for a number of file formats
  5. <IfModule mod_mime.c>
  6. AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml
  7. </IfModule>
  8.  
  9. # FileETag None is not enough for every server.
  10. <IfModule mod_headers.c>
  11. Header unset ETag
  12. </IfModule>
  13.  
  14. # Since we’re sending far-future expires, we don’t need ETags for static content.
  15. FileETag None
  16.  
  17. <IfModule mod_alias.c>
  18. <FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$">
  19. <IfModule mod_headers.c>
  20. Header unset Pragma
  21. Header append Cache-Control "public"
  22. Header unset Last-Modified
  23. </IfModule>
  24. </FilesMatch>
  25.  
  26. <FilesMatch "\.(css|htc|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
  27. <IfModule mod_headers.c>
  28. Header unset Pragma
  29. Header append Cache-Control "public"
  30. </IfModule>
  31. </FilesMatch>
  32. </IfModule>
  33.  
  34. # Gzip Compression
  35. <IfModule mod_deflate.c>
  36. # Force compression for mangled headers.
  37. <IfModule mod_setenvif.c>
  38. <IfModule mod_headers.c>
  39. SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  40. RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  41. # Don’t compress images and other uncompressible content
  42. SetEnvIfNoCase Request_URI \
  43. \.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g|mp4|webm|webp|pdf)$ no-gzip dont-vary
  44. </IfModule>
  45. </IfModule>
  46. # Compress all output labeled with one of the following MIME-types
  47. <IfModule mod_filter.c>
  48. AddOutputFilterByType DEFLATE "application/atom+xml" \
  49. "application/javascript" \
  50. "application/json" \
  51. "application/ld+json" \
  52. "application/manifest+json" \
  53. "application/rdf+xml" \
  54. "application/rss+xml" \
  55. "application/schema+json" \
  56. "application/vnd.geo+json" \
  57. "application/vnd.ms-fontobject" \
  58. "application/x-font-ttf" \
  59. "application/x-javascript" \
  60. "application/x-web-app-manifest+json" \
  61. "application/xhtml+xml" \
  62. "application/xml" \
  63. "font/eot" \
  64. "font/opentype" \
  65. "image/bmp" \
  66. "image/svg+xml" \
  67. "image/vnd.microsoft.icon" \
  68. "image/x-icon" \
  69. "text/cache-manifest" \
  70. "text/css" \
  71. "text/html" \
  72. "text/javascript" \
  73. "text/plain" \
  74. "text/vcard" \
  75. "text/vnd.rim.location.xloc" \
  76. "text/vtt" \
  77. "text/x-component" \
  78. "text/x-cross-domain-policy" \
  79. "text/xml"
  80. </IfModule>
  81. <IfModule mod_headers.c>
  82. Header append Vary: Accept-Encoding
  83. </IfModule>
  84. </IfModule>
  85.  
  86. <IfModule mod_mime.c>
  87. AddType text/html .html_gzip
  88. AddEncoding gzip .html_gzip
  89. </IfModule>
  90. <IfModule mod_setenvif.c>
  91. SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip
  92. </IfModule>
  93.  
  94. # Expires headers
  95. <IfModule mod_expires.c>
  96. ExpiresActive on
  97. ExpiresDefault "access plus 1 month"
  98.  
  99. # cache.appcache needs re-requests in FF 3.6
  100. ExpiresByType text/cache-manifest "access plus 0 seconds"
  101.  
  102. # CSS
  103. ExpiresByType text/css "access plus 1 year"
  104.  
  105. # Data interchange
  106. ExpiresByType application/json "access plus 0 seconds"
  107. ExpiresByType application/xml "access plus 0 seconds"
  108. ExpiresByType text/xml "access plus 0 seconds"
  109.  
  110. # Favicon (cannot be renamed!)
  111. ExpiresByType image/x-icon "access plus 1 week"
  112.  
  113. # HTML components (HTCs)
  114. ExpiresByType text/x-component "access plus 1 month"
  115.  
  116. # HTML
  117. ExpiresByType text/html "access plus 0 seconds"
  118.  
  119. # JavaScript
  120. ExpiresByType application/javascript "access plus 1 year"
  121.  
  122. # Manifest files
  123. ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
  124. ExpiresByType text/cache-manifest "access plus 0 seconds"
  125.  
  126. # Media
  127. ExpiresByType image/gif "access plus 1 month"
  128. ExpiresByType image/jpeg "access plus 1 month"
  129. ExpiresByType image/png "access plus 1 month"
  130. ExpiresByType video/mp4 "access plus 1 month"
  131. ExpiresByType audio/ogg "access plus 1 month"
  132. ExpiresByType video/ogg "access plus 1 month"
  133. ExpiresByType video/webm "access plus 1 month"
  134.  
  135. # Web feeds
  136. ExpiresByType application/atom+xml "access plus 1 hour"
  137. ExpiresByType application/rss+xml "access plus 1 hour"
  138.  
  139. # Web fonts
  140. ExpiresByType application/font-woff "access plus 1 month"
  141. ExpiresByType application/font-woff2 "access plus 1 month"
  142. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  143. ExpiresByType application/x-font-ttf "access plus 1 month"
  144. ExpiresByType font/opentype "access plus 1 month"
  145. ExpiresByType image/svg+xml "access plus 1 month"
  146. </IfModule>
  147.  
  148. # Send CORS headers if browsers request them; enabled by default for images.
  149. <IfModule mod_setenvif.c>
  150. <IfModule mod_headers.c>
  151. # mod_headers
  152. <FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
  153. SetEnvIf Origin ":" IS_CORS
  154. Header set Access-Control-Allow-Origin "*" env=IS_CORS
  155. </FilesMatch>
  156. </IfModule>
  157. </IfModule>
  158.  
  159. # Webfont access
  160. <IfModule mod_headers.c>
  161. <FilesMatch "\.(tt[cf]|otf|eot|woff|woff2|font.css|css|js)$">
  162. Header set Access-Control-Allow-Origin "*"
  163. </FilesMatch>
  164. </IfModule>
  165. ### End Caching Performance ###
Advertisement
Add Comment
Please, Sign In to add comment