Thursday, September 14, 2006

setting Expires with web server

Expiration date can be set in web server configuration for static resources [dynamic resources can have Expires set by scripts].

Apache Expires can be set in the configuration file [httpd.conf] or with .htaccess files. In any case expires_module must be active. While .htaccess files are more flexible, allowing changes without server restart [and sometimes are the only choice available], there is a performance impact: each time a file is requested Apache must process directory's .htaccess file as well as every one that exists up to the server root.

The following example ensures that all "*-stable.pdf" files are cacheable for one year from the time they are requested. To use inside httpd.conf <Directory> or <Location> directives, or in .htaccess files:

<IfModule mod_expires.c>
  ExpiresActive On
  <FilesMatch "-stable\.pdf$">
    ExpiresDefault "access plus 1 year"
  </FilesMatch>
</IfModule>
[actually, <FilesMatch> doesn't match with <Location> :/]

IIS Expires can be set with IIS Manager [control panel / administrative tools]. When you set Expires for a server or directory that applies to all files under:

  • Select server, directory or file properties with menus.
  • In properties dialog select the HTTP headers tab.
  • Select a relative [to access date] or absolute expiration time.

0 Comments:

Post a Comment

<< Home