Page Index Toggle Pages: 1
Topic Tools
Normal Topic caching via htaccess (Read 1,080 times)
freediver
Senior Member
****
Offline



Posts: 518
caching via htaccess
Dec 24th, 2012 at 1:34am
Post Tools
I am trying to figure out how caching via htaccess works. My host suggested this:

Quote:
There are also a lot of resources that can be cached by the browser, but are not specifying expiration, so are not able to be. This can be corrected by adding something like the following to your .htaccess file:

Code
Select All
<filesmatch "\.(flv|gif|ico|jpg|jpeg|png|swf)$">
header set Cache-Control "max-age=2592000"
</filesmatch>
<filesmatch "\.(css|js|pdf|txt)$">
header set Cache-Control "max-age=604800"
</filesmatch>
<filesmatch "\.(html|htm)$">
header set Cache-Control "max-age=43200"
</filesmatch>
<filesmatch "\.(cgi|fcgi|php|pl|scgi|spl)$">
header unset Cache-Control
<ifmodule mod_expires.c>
expiresactive off
</ifmodule>
</filesmatch>
<ifmodule mod_expires.c>
expiresdefault "access plus 1 year"
</ifmodule> 



I am not sure which htaccess file to edit, as I understand that you can have a different one in each folder. If I change the one in the root (public_html) folder, will that cascade down to all the subfolders?

Does anyone have tips on appropriate settings?

Should I set them all so that browsers always check if the file has been updated?
« Last Edit: Dec 24th, 2012 at 1:43am by freediver »  

Founding member of . I recently upgraded from YaBB 2.2.1 to 2.5 AE to 2.5.2.
Back to top
WWW  
IP Logged
 
freediver
Senior Member
****
Offline



Posts: 518
Re: caching via htaccess
Reply #1 - Dec 25th, 2012 at 9:12am
Post Tools
This is what I went with, in the .htaccess file in the public_html folder:

Code (HTML)
Select All
<filesmatch "\.(flv|gif|ico|jpg|jpeg|png|swf|bmp|giff|css|js|pdf|txt)$">
header set Cache-Control "max-age=604800"
</filesmatch>
<filesmatch "\.(html|htm)$">
header set Cache-Control "max-age=43200"
</filesmatch>
<filesmatch "\.(cgi|fcgi|php|pl|scgi|spl)$">
header unset Cache-Control
<ifmodule mod_expires.c>
expiresactive off
</ifmodule>
</filesmatch>
<ifmodule mod_expires.c>
expiresdefault "access plus 24 hours"
</ifmodule>  



My understanding is that image files will be cached for 1 week, and html for 12 hours. Scripts have all caching information stripped so that the user's browser decides on caching. (Is that a bad idea?) I am not sure what the last bit covers so I set it to one day.

I am thinking of adding a 1 minute cache to script files, to cover users going forward and back. Thoughts?

Are yabb template html files sent to the client browser or handled by the server?
« Last Edit: Dec 25th, 2012 at 9:18am by freediver »  

Founding member of . I recently upgraded from YaBB 2.2.1 to 2.5 AE to 2.5.2.
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Topic Tools
 
  « Board Index ‹ Board  ^Top