Forum Moderators: phranque

Message Too Old, No Replies

Apache caching

best approach for ordinary files

         

smallcompany

8:38 am on May 26, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Until fairly recently, I used shared hosting for my sites. Now I also have a VPS server in my portfolio.

My understanding is that it is better to configure caching right in the Apache config file, rather than in .htaccess - as long as I know what I want for the sites being run on that VPS.

So, if I know that I want to have same configuration for all of the sites when about browser cache settings for images, CSS, javascript, and HTML files, what should I do?
Is it just about editing httpd.conf or there's more to it?
When I checked a page about caching at Apache's site... phew... too many things as caching is not only about client side, but there are all sorts of cache related configurations on the server itself.
I don't want to run away from all of that. In contrary, I would like to use an opportunity and give a chance to that server to run fast.

How would you outline main steps for configuring caching on Apache server, including both client and server side (if it can be said in that way)?

Thank you

topr8

9:32 am on May 26, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>My understanding is that it is better to configure caching right in the Apache config file, rather than in .htaccess

slightly OT, it is actually better to diasable .htaccess and put all directives in the configuration file/s.

do i understand that you want to direct the browser to cache .css .jpg files etc for a certain length of time.
if so then in http.config you would want something like this ...
inside the root document directory for the webserver (this way it would apply to all the sites you have)

you must have turned on: mod_expires


<Directory "/var/www/html">

... there will probably be a bunch of directives already here

ExpiresActive On
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpg A604800


</Directory>


A stands for access and the number represents the number of seconds the file should be cached for.

... the client can over-ride your settings though, if they choose to.

relevant documentation is here ... [httpd.apache.org...]

lucy24

6:02 pm on May 26, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it is better to configure caching right in the Apache config file, rather than in .htaccess

In most situations-- the biggest exception I can think of involves compiling regular expressions-- it doesn't matter where a command is located. The only thing that matters is whether an htaccess file exists at all. Or, more accurately, whether it is potentially allowed to exist. The directives themselves will normally be identical.

To expand what topr said: designate one directory for testing, and set wide-ranging AllowOverride for that one directory so you can make htaccess changes on the fly without having to stop and start the server. (You will also want to do things like set shorter expiration times so you don't need to reload or refresh. My test site has expiration set to "access" for html and php files.) Everywhere else, don't allow overrides, but keep all directives in the config file itself.

This is not entirely tangential, because it's possible that this is actually what your source meant: not where, but whether.