Page 1 of 1

Speed up your website by compressing and caching with .htaccess

Posted: Fri Nov 04, 2016 6:08 am
by arnlweb
This .htaccess file example that will gzip your text files (_.css, _.js, _.html, _.html, _.xhtml, and _.php) and it will cache all your static files, may look like:

Code: Select all

# BEGIN Compress text files (ARNLWEB)
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
# END Compress text files (ARNLWEB)

# BEGIN Expire headers (ARNLWEB)
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
# END Expire headers (ARNLWEB)

# BEGIN Cache-Control Headers (ARNLWEB)
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
# END Cache-Control Headers (ARNLWEB)

# BEGIN Turn ETags Off (ARNLWEB)
<ifModule mod_headers.c>
  Header unset ETag
FileETag None
# END Turn ETags Off (ARNLWEB)

# BEGIN Remove Last-Modified Header (ARNLWEB)
<ifModule mod_headers.c>
  Header unset Last-Modified
# END Remove Last-Modified Header (ARNLWEB)