Forum

Images Expire

Remco
3 June 2009, 11:07
Is it possible to set the expire-flag for images?

Hiawatha version: Hiawatha v6.11, cache, IPv6, SSL, URL toolkit
Operating System: OpenSuse 11.1
Hugo Leisink
3 June 2009, 13:28
Not via Hiawatha. But you can do the following trick: use the URL toolkit to redirect every request in a specific directory to a PHP script and let that PHP script use header() to set the expire flag and readfile() to output the image. Don't forget to use header("Content-Type: image/<type>") to set the correct content type of the image.

UrlToolkit {
ToolkitID = images
Match ^/images/.* Rewrite /images.php
}

VirtualHost {
...
UseToolkit = images
}


Use $_SERVER["REQUEST_URI"] in your PHP script to find out which file was requested. If a non-existing file was requested, use header("Status: 404") to generate a 404 error.
Remco
3 June 2009, 15:21
This is not the solution I was hoping for.

Is it do-able to add this support in a newer version of Hiawata? If not, is there a good reason why this feature isn't included.

Thanks
Hugo Leisink
3 June 2009, 16:32
Can you give me more detailed information about what you want to achieve?
Remco
3 June 2009, 17:34
It's not a matter of life or death, however, adding an expire header to images will reduce server requests for files that will not be changed in future.

http://developer.yahoo.net/blog/archives/2007/05/high_performanc_2.html

But maybe I'm a little bit too enthusiastic. Hiawatha is intended to be a lightweight web server after all(?).
Hugo Leisink
3 June 2009, 18:31
Hiawatha adds a Last-Modified header line to every request-answer. It contains a timestamp of the last modification of a file. All modern webbrowsers add a If-Modified-Since header to every request. Via that, Hiawatha can see if the browser's cache contains the same version as it has on disk. If that's the case, Hiawatha sends a 304 Not Modified answer with no content. The browser will use the file from its cache. That's the mechanism that's being used by webservers and webbrowsers to safe bandwidth. It's a reliable system, so my advice is not to toy around with expire flags.
Remco
3 June 2009, 20:40
Ok, thanks for your explanation.
This topic has been closed.