I have just received an email from Anja giving me her blessing for implementing her “sidewinder” idea in my weblog.
The Flickwerk weblog is a static file rendered by the wickedly cool Tinderbox.
I couldn’t figure out how to get MovableType to sort out blog entries by months and render them into the index page. Instead I setup a simple template to render relatively plain monthly archives with the names plain_YYYY_MM.html. Then I wrote a little index.php, which looks for these monthly archive files and sort them into the right order. Index.php then reads these files and render the page.
The first version was slow, ‘cos PHP had to read the whole directory, read all the relevant files into memory, then send everything out, and it had to do it for each request.
Then I built caching into the second version (current version), which renders and stores the generated page in a cache file in /tmp. Everytime there is a request, index.php goes thru the list of monthly archive files and check their last change times against that of the cache file, and send the cache file if it is up-to-date. This version seems faster, but I have no figures to support this. Some quantitative tests in due course.
The next version will implement proper HTTP headers, including web caching (e.g. squid proxy) control.
In her email, Anja commented that:-
I don’t know if PHP decreases the load a little, but I found that with a full year of posts on one page, loading-time becomes rather modem-unfriendly (esp. with pictures).
The Flickwerk page is 155KB. Mine is a good fat 540KB! Although PHP is fast, it would still have a negative impact on the response of the site. At least the layout is not done with tables, by which the page is only viewable after the whole page is loaded.
The first step to improve the load time is to cut content, e.g. send only six months’ worth of blog. This should immediately cut the page size by half.
The next step is to enable HTTP compression, probably with mod_gzip on Apache. On the couple of times I played with Apache, PHP and mod_gzip they never really worked together properly for some unknown reasons (probably my own fault), but in this case I’ll look into doing it all with PHP and raw gzipped cache file, which means the same output is only ever compressed once, saving the trouble of involving mod_gzip for every request.
Update (23:24) It was a piece of cake. Cache file is now in gzip format and is sent directly to the browser. File size is now down to 115KB.