Page 1 of 1

Leverage Browser Caching

Posted: Thu May 06, 2010 8:46 am
by danst0
Hi,

just ran page speed (plugin for firefox) on my s9y blog. The major improvement possibility seams to be an increased usage of browser caching.

There are different kinds of pictures involved:
plugin: plugins/serendipity_plugin_twitter/img/tt-micro-black.png
style: templates/joshua_nino/img/bodybg.png
own uploads: uploads/Images/CC_88x31.png
s9y: serendipity.css

Can somebody tell me how I could turn on browser caching for them?

Thank you,

Daniel

Re: Leverage Browser Caching

Posted: Thu May 06, 2010 10:30 am
by garvinhicking
Hi!

Those pictures are straightly served from your webserver, so you need to enable that in your Apache configuration:

http://httpd.apache.org/docs/2.0/mod/mod_expires.html

Regards,
Garvin

Re: Leverage Browser Caching

Posted: Fri May 07, 2010 9:00 am
by konus
Yes that ist right, you can do it with mod_expires and eventually mod_headers.

My provider did not install those modules, because of php-fcgi. That is why I found an other way to do the same job. I put the following lines into .htaccess

Code: Select all

#Leverage browser caching
<FilesMatch "\.(gif|flv|jpg|jpeg|png|gif|swf)$">
	FileETag -INode MTime Size
        # if you use ETags, you should unset Last-Modified
        Header unset Last-Modified
        Header set Cache-Control "max-age=604800, public, must-revalidate"
        Header set Expires "Thu, 31 Dec 2010 20:00:00 GMT"
    </FilesMatch>
    <FilesMatch "\.(gz)$">
        FileETag None
        Header set Cache-Control "max-age=604800, public, must-revalidate"
        Header set Expires "Thu, 31 Dec 2010 20:00:00 GMT"
    </FilesMatch>
    <FilesMatch "\.(js|css)$">
        FileETag None
        Header set Cache-Control "max-age=28800, public, must-revalidate"
        Header set Expires "Thu, 31 Dec 2010 20:00:00 GMT"
    </FilesMatch>

Re: Leverage Browser Caching

Posted: Fri May 07, 2010 9:09 am
by konus
Enabling gzip compression is considered as another option to enhance the speed. In my case, only php/html-files where gzipped, but no css and js files. I learned I would need the Module mod_deflate for this an add to .htaccess

Code: Select all

<FilesMatch "\.(css|js|xhtml|html|htm|php)$">
    SetOutputFilter DEFLATE
</FilesMatch>
or

Code: Select all

#AddOutputFilterByType DEFLATE text/html text/plain text/xml   
Because my provider did not install mod_deflate I found an other way to offer gzip compression. I gzipp'ed the css and js files manually with 7-zip. Than I added to .htaccess

Code: Select all

# BEGIN Gzip Compression
AddEncoding gzip .gz
<filesmatch "\.css\.gz$">
  AddType "text/css" .gz
</filesmatch>
<ifmodule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME} \.(js|css)$
  RewriteCond %{REQUEST_FILENAME}.gz -f
  RewriteRule ^(.*)$ $1.gz [QSA,L]
</ifmodule>
Be warned, some older browsers (like IE6) have problems with gziped-files so maybe a browser condition has to be added.

Re: Leverage Browser Caching

Posted: Tue May 11, 2010 11:41 am
by danst0
Thanks for the hints, until I receive an answer from godaddy concerning my mod_expires activation, I am going with your browser caching solution.

The SetOutputFilter DEFLATE worked well for me!

Thanks,

Daniel