Leverage Browser Caching

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Leverage Browser Caching

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Leverage Browser Caching

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
konus
Regular
Posts: 334
Joined: Mon Jun 16, 2008 1:57 pm
Location: Dresden, Germany
Contact:

Re: Leverage Browser Caching

Post 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>
konus
Regular
Posts: 334
Joined: Mon Jun 16, 2008 1:57 pm
Location: Dresden, Germany
Contact:

Re: Leverage Browser Caching

Post 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.
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Leverage Browser Caching

Post 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
Post Reply