Source Code

Speed Up Web Access Using Cache in Apache

  • anonymous
  • Aug 13' 14
  • htaccess
  • 66
  • 240
  • United States

This script can accelerate the process of loading page your website, by using Apache on an Htaccess file.

we will deflate module that bundled on apache default, below sample script to compress with gzip

<ifModule mod_deflate.c>
  <filesMatch ".(html|css|js|php)$">
   SetOuputFilter DEFLATE

They will compress files with extension .html .css .js and .php

For complete function caching use this:

#First Compress
<ifModule mod_deflate.c>
  <filesMatch ".(html|cssjs|php)$")
   SetOutputFilter DEFLATE

#Second set the expiration
<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 text/css "access plus 604800 seconds"
 ExpiresByType text/javascript "access plus 216000 seconds"
 ExpiresByType text/html "access plus 600 seconds"
 ExpiresByType application/xhtml+xml "access plus 2592000 seconds"

# BEGIN Cache-Control Headers
<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
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
FileETag None
# END Turn ETags Off
# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
  Header unset Last-Modified
# END Remove Last-Modified Header




  • Tags : apache, caching, web, speed up
comments powered by Disqus

Related Code

Apache setting for CodeIgniter when upload in sub domain

Proteksi Server Web dari serangan DOS/DDOS/BruteForce