When we first started building our site with Textpattern, we noticed sluggish page load times that seemed downright unacceptable. After a bit of research and fiddlin’, we finally got out of Textpattern the performance we’re used to seeing on static page managers. The following tips are for the 1.0rc3 version of Textpattern.
1. Turn off logging.
Go to the Admin tab and set Logging to “None” in your Site Preferences. I know it’s convenient to see stats in one place, but there’s better software for tracking those numbers that should have come with your hosting plan. Awstats is a nice one for pretty and details, but we’ve started taking a liking to Shaun Inman’s nimble Shortstat. Unfortunately, Shortstat doesn’t work right out of the box for 1.0rc3.
To make Shortstat fly in Textpattern, change the code in your ‘index.php’ file from this:
<?php $here = dirname(__FILE__); include './textpattern/config.php'; include $txpcfg['txpath'].'/publish.php'; textpattern(); ?>
<?php $here = dirname(__FILE__); include 'textpattern/config.php'; include $txpcfg['txpath'].'/publish.php'; textpattern(); include_once($_SERVER["DOCUMENT_ROOT"]."/shortstat/inc.stats.php"); ?>
Yeah, you just add one line. If you’re using an older version of Textpattern, try Hick’s fix.
If you must have Textpattern’s built-in logging, you could turn off DNS lookup to reduce server processing time. Inside the ‘lib’ folder in your textpattern directory, there’s a nice little file called ‘admin_config.php’. Take a look inside there and set ‘use_dns’ to ‘0’.
2. Turn off/on Send Last-Modified Header.
This is also in your Site Preferences under the Admin tab. Even though this is meant to make pages load faster, I’ve seen reports and anecdotes about things improving / getting worse while having it on / off. Obviously, your mileage will vary.
FYI : We have it on.
AFAIK the relevant code is commented out in the code base anyway, so you shouldn’ actually see a difference no matter wether you turn it on or off. (publish.php line 163ff., but it’s safe to uncomment it and turn it on) :)
3. Don’t use the built in css editor.
Hate to say it because I think it’s genius, but we noticed a huge decrease in the render time of our pages (you can find it by viewing the source and looking at the bottom of the html) after we made the css file a physical one on the server. It’s not a huge problem to my workflow, because I usually just use View/Edit on my ftp program of choice (Filezilla for pc and Transmit for mac) for quick css editing. If I only have access to a browser there’s always net2ftp or, when I’m desperate, the filebrowser on my cpanel.
4. Turn on gzip compression for php, css and js files.
Using gzip compression was a tip we got from John Hicks. This is actually good for any site, not just Textpattern because it will usually decrease the size of the files served to the user by at least 60%. There are literally over a half a million sites dedicated to doing this one thing. Here’s how we implemented it on our server.
First, we added the following lines to our ‘.htaccess’ file to turn on gzip compression.
php_flag zlib.output_compression On php_value zlib.output_compression_level 5
Now, all our php files will be compressed before they’re served to the user. To turn on gzip for css and javasript files, we have to make the server think that css and js files are basically php too. To do that, we add the following line to ‘.htaccess’
AddHandler application/x-httpd-php .css .js
The problem is the content-type headers of our css an js files will now look like php application files and won’t be rendered properly in certain browsers like Firefox nor validate on the W3C CSS Validator. To fix this, we created a file called ‘contentHeader.php’ in a folder called ‘includes’with the following code:
php_value auto_prepend_file /yourdirectoryto/includes/contentHeader.php
Well, that should do it. If you’ve got additional suggestions for speeding up Textpattern, let us know and we’d be happy to check them out and add them here.