Forum Moderators: phranque

Message Too Old, No Replies

Force browser to cache files

         

GetFree

8:19 pm on Dec 9, 2006 (gmt 0)

10+ Year Member



I want to send the browser some headers to force it to cache .js and .css files.

Is there any way to configure apache to do this (using .htaccess)?

Thanks.

jd01

8:38 pm on Dec 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would start with:

Mod_Expires [httpd.apache.org] AND Mod_Cache [httpd.apache.org] THEN Mod_Headers [httpd.apache.org]

This should give you some ideas.

Some hosts may not have the module(s) you need loaded, so you could have to implement a work-around.
EG I set the expires of my html pages with a php script, and use:

Header unset Cache-Control
Header set Cache-Control: "public,max-age=604800"

For all other files to be cached for one week.

Justin

GetFree

10:38 pm on Dec 9, 2006 (gmt 0)

10+ Year Member



Thank you Justin. That's just what I need.

I get a "Internal Server Error" message when I use the Header directive. I guess that means the module is not available.

GetFree

10:02 pm on Dec 10, 2006 (gmt 0)

10+ Year Member



Just one last question.

The Header directive will affect EVERY file in the directory where the htaccess file is located and all its sub-directories, right?

jdMorgan

10:25 pm on Dec 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Standing alone, yes it will.

You can wrap it in a <Files> or <FilesMatch> container to make it conditional if needed.

Jim