Forum Moderators: phranque

Message Too Old, No Replies

stop server caching

stop server caching

         

Net Explorer

5:12 pm on Oct 18, 2005 (gmt 0)



How can I stop my site files being cached on the server?

Can I use htaccess to force a new file every time the page is called? Can this work for images/swf/etc?

thanks in advance

jdMorgan

10:26 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume you mean you want to stop caching in the client browser, but do you really want to do that? It will increase your server load significantly if so.

Usually, a compromise approach works better -- Allow caching, but for only a limited amount of time.

A combination of Apache mod_expires and mod_headers can be used to control caching:


# Set up Cache Control headers
ExpiresActive On
# Default - Set http header to expire everything 1 week from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "must-revalidate"
# Apply a customized Cache-Control header to image files
<FilesMatch "\.(swf¦gif¦jpg)$">
ExpiresDefault A60
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
# Mark error pages as non-cacheable
<FilesMatch "^(401¦403¦404¦410)\.html$">
ExpiresDefault A1
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>

Change all broken pipe "¦" characters to solid pipe characters before use. Flush your browser cache before testing.

Jim