You are here:Home»KB»Web Server»htaccess»caching with htaccess
Tuesday, 14 February 2017 14:13

caching with htaccess

Written by

This is an email I sent with information on caching by htaccess.


Hi Vlado

Just a quick update and the information on caching I have.

I mentioned that the jotcache component showed entries even after I had emptied the joomla cache. You advised me to hit refresh. This worked. Perhaps an automatic refresh when the component is launched might help.

The Expires plugin fails with the normal joomla cache as well so I will contact the plugin author about this as it appears to be a fault or missing feature with this plugin.

Cache

I am still experimenting with cache for my website. I do not know how much you know about this so if my reply is basic please don’t be offended.

I am currently setting everything to one hour so I can test things without leaving unwanted cached items on peoples browsers. I intend to move these to 1 day when I have finshed developing. Google prefers expires (because more compatible) and to have them set to one month, this might have an effect on SEO.

My cache is set both in the htaccess file and in the expires plugin and jotcache (different type of cache and you already know its feature and power)

htacess

This is the rule I am working with at the minute, I have included both types of cache for testing but cache-control overrides expires anyway. I have also put them inside a filesmatch rather than globally, this would be fine aswell. last modified is unset because I am using cache-control to set freshness of the files and it is an overhead that is not needed. This assume fairly static content. However if you set a max-age of only an hour it is not really an issue a user having out of date content

## My Cache Rule - check whether ExpiresActive is required here
# All specified files can be cached in public/private proxies and browsers etc..and when it expires must revalidate 
<FilesMatch "\.(ico|pdf|flv|gif|jpg|JPG|jpeg|JPEG|png|PNG|swf|css|js|js\.gz|gz|htm|html|xml|txt)$">
    Header set Cache-Control "max-age=3600, public, must-revalidate"
    ExpiresActive On
    ExpiresDefault "now plus 1 hour"
    Header unset Last-Modified
</FilesMatch>

This rule set below is the same as above but the cache control is slightly different, it has a private option set, this means that no public proxy or cache can store this data, only a cache that the user has private access to  ie internet explorer cache

## My Shop Cache Rule - check whether ExpiresActive is required here
# All specified files can be cached in browsers but not public caches/proxies etc..and when it expires must revalidate
# bbc.co.uk uses private
<FilesMatch "\.(ico|pdf|flv|gif|jpg|JPG|jpeg|JPEG|png|PNG|swf|css|js|js\.gz|gz|htm|html|xml|txt)$">
    Header set Cache-Control "max-age=3600, private, must-revalidate"
    ExpiresActive On
    ExpiresDefault "now plus 1 hour"
    Header unset Last-Modified
</FilesMatch>

You mention in your email - (a problem with this at the minute is joomla does not set a Last Modified Header, I need to look in to this further but the theory still stands)

For general usage I think here is necessary that browser at least make a ping to server and this one responds with 304 code.

This can be achived better by using a cache control setting off

Header set Cache-Control "max-age=3600, no-store, public, must-revalidate"

The no-store actually means that the browser cannot use the content in its browser without first revalidating the content with the original source. However this method with not depend on the session still being open like with the 'Use Browser Cache option'. When using this either ETag or Last Modified header need to be set, as ETAGs are problematic everyone uses Last Modified Header, so in this case I would not unset Last Modified asa it is needed to revalidate content.

My settings that I am will be testing on my Expires plugin:

1 hour, Public, Must Revalidate

I will also give you these links which I found very helpful in understanding cache:

I hope this helps. I am currently writing a htaccess files with a really good cache section in it. If you would like a copy of it I can send it you. I would send it now but I don’t want the email to end up in spam.

One last question. Does joomlas cache/jotcache store html headers in the cache or just the html page content?

Thanks

Shoulders

Read 955 times