Forum Moderators: open

Message Too Old, No Replies

Cache-Control Headers

where does the code go?

         

kindred1

11:43 am on Sep 17, 2005 (gmt 0)

10+ Year Member



Im trying to use the Cache-Control Headers,but im nto sure where the code goes in my HTML. can someone help or show me an example? not sure where or how to format this code
Cache-Control: max-age=9600, must-revalidate

thanks alot for any help

Using Cache-Control headers

The first way, and the one we generally recommend, is to add the Cache-Control header mentioned above. The general format is:

Cache-Control: max-age=num_seconds

where num_seconds is the amount of time in seconds you want the page to last before it expires.

encyclo

8:30 pm on Sep 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code doesn't go in your HTML - there are HTTP headers, which are sent before the page itself. You have two options: the first is to configure your web server software to send them (for example via .htaccess with Apache), or you can also set them with a server-side scripting language such as PHP. An example:

<?php
header("Cache-Control: must-revalidate");
?>

The headers must be set before any content, otherwise they will trigger an error.

kindred1

11:37 pm on Sep 19, 2005 (gmt 0)

10+ Year Member



thanks,ill ask our server tech about forcing a recache on our home page every so often.

would this work in the actual file?

<META HTTP-EQUIV="Cache-Control" CONTENT="max-age=86400, must-revalidate">

bull

9:26 am on Sep 20, 2005 (gmt 0)

10+ Year Member



It can go as well in your .htaccess file, if the mod_headers Apache module is installed:

Header add Cache-Control "must-revalidate"

kindred1

9:50 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



id like to use it in my htaccess,can you post the exact code i need? im seeing so many versions online,im not sure whick to use..

thanks a ton guys!

bull

1:49 pm on Sep 25, 2005 (gmt 0)

10+ Year Member



in your .htaccess :
Header unset Cache-Control:
Header append Cache-Control: "max-age=86400, must-revalidate"

Note: as said, this only works if mod_headers is installed. If your server returns a "500" error after you inserted this code, you cannot use the .htaccess variant