Podcasting should not be expensive - Part 3

In Part 2, I set up my site's .htaccess file to redirect requests from my media directory to the Coral Content Distribution Network. As I monitored my logs, I saw that Coral requested my first podcast about twice a day. That's because my site wasn't telling Coral how long it was safe to cache the file. Coral could also request the file more often than expected if it was flushed from the cache by other files, but there's nothing I can do about that.

Coral is sort of an opt-in cache, in that I am redirecting my users to the cache. There are many other caches on the web though. ISPs use them to speed up their customers' access to popular sites. Many businesses that use a proxy server for web access also turn on the proxy's cache, so that when everyone goes to the popular sports and news sites they doesn't clog the internet connection. This type of cache is called a transparent cache because it sits between the end user and the internet and substitutes cached resources for requested remote resources. There's nothing you can do about these caches, but you can help them help you by telling them how long your files are valid.

Once again, an .htaccess file comes into play. I put the following .htaccess file in my media directory:

ExpiresActive On
ExpiresDefault "access plus 1 year"

The first line turns on expiration headers. The second line sets the default expiration time for files in the directory to the time of last access plus one year. You could use 1 month or 1 day if you're more comfortable with that. I don't expect the files in my media directory to change. I didn't see any point in setting the expiration any longer than a year, because it's doubtful any cache would keep a file that long if nobody requested it. I also expect people to download files from links on my pages or feeds, so if I do need to replace a file, I can simply rename it and change my link. You can check that the expiration headers are being sent by using a program that shows you the headers. Most download managers do this. You should see something like this in the headers:

cache-control: max-age=31536000
expires: Thu, 23 Nov 2006 00:17:49 GMT

Note that the time on the first line is in seconds. You may need to ask your hosting provider to include the mod_expires module so you can use expiration headers. So far, my host Dragonfort has had everything I've needed available. Here's a link to the documentation for mod_expires on the Apache website.

You might wonder why I haven't set up expiration headers for things like my main page. I will, but there's something else I need to do first. Also, I said above that I don't expect the files to change, but I didn't say they were going to stay on my server. Stay tuned.

Comments are closed.

Bad Behavior has blocked 33 access attempts in the last 7 days.

Creative Commons License