For Apache, you can make use of the htaccess
file with the cache control directives that tell browsers how long they should download a new version of each file.
Some examples:
Header unset Pragma
FileETag None
Header unset ETag
# 1 Ano (limitado a ficheiro media)
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
# 2 Horas (limitado a ficheiro conteúdos)
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
# Em cache para sempre (scripts e folhas de estilo)
<FilesMatch "\.(js|css)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
Example of caching in CSS files limited to 3 days
Create .htaccess
file in the root of the folder containing the target files;
Write the appropriate cache control into the file;
Indicate the file extensions assigned to the control to be applied:
# extensões separadas por um |
<FilesMatch "\.(css)$">
Specify the duration of the cache so that the server tells the browser that a certain file is only valid for the time indicated, after which another one must be collected:
# max-age = XX segundos
Header set Cache-Control "max-age=259200, must-revalidate"
The result of the file to use is:
Header unset Pragma
FileETag None
Header unset ETag
# 3 Dias
<FilesMatch "\.(css)$">
Header set Cache-Control "max-age=259200, must-revalidate"
</FilesMatch>