Web Design

Related Tags:

blogging Business How To HTML Humor Innovation PHP plugins Programming The Internet Ultimate-Tag-Warrior usability Web-Development WordPress

WordPress Tutorial: Using WP-Cache on Windows / IIS

Is your blog starting to bog down? Getting nasty emails from your ISP about overloading the database server? Since most blogs are read far more often than they are updated, caching your pages can result in a real performance improvement.

Wordpress has some very basic object caching, but you really need to be able to cache whole pages to see a big benefit. Luckily there is a very good page-caching plugin, WP-Cache.

If you are on a Linux or Unix host, installation is pretty straightforward.

Now, what if you are on a Windows/ IIS host and using 'date and name based', almost-pretty permalinks? No sweat. Okay, a little bit of sweat.

The code for WP-Cache makes a few assumptions about the environment it's running in which don't work out so well in Windows. My first major step in getting it to work was a great blog post on CPUIdle. Since that blog seems to be down, I'll quote their steps here:

"1. Download WP-Cache zip file (current version as of writing is 2.0.17) and unzip into wp-content/plugins folder.

2. Copy wp-content/plugins/wp-cache/wp-cache-phase1.php to wp-content/advanced-cache.php (not really sure why this isn’t simplified by the author).

3. Open the standard wp-config.php file and add define('WP_CACHE', true);

4. Now comes the tricky part:

open wp-content/plugins/wp-cache/wp-cache.php in your favourite text editor. Search for the wp_cache_add_pages function and change the function code like this:

add_options_page('WP-Cache Manager', 'WP-Cache', 5, 'wp_cache/wp_cache.php', 'wp_cache_manager');

Reason the original code doesn’ work is that the original __FILE__ resolves to wp_cache\wp_cache.php which some browser eat and convert to wp_cachewp_cache.php- which doesn’t exist.

5. Second problem is that WP-Cache checks for installation step 2) in a windows-incompatible manner. Search for the wp_cache_check_link function. Change the first three lines after the variable declaration in this way:

# if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {

# @unlink($wp_cache_link);

# if (!@symlink ($wp_cache_file, $wp_cache_link)) {

if (!file_exists($wp_cache_link)) { {

6. Finally, open wp-content/plugins/wp-cache/wp-cache-phase2.php and search for ob_end_clean(); and replace with ob_end_flush();. Without this change the cached page contents are not written back when the page is initially cached. It’s unclear to me if that works under *nix, I assume it couldn’t.

7. That’s it- you’re done. No goto Options/WP-Cache and turn caching on."

Unfortunately, if you are set up like we are, using the “index.php� style permalinks, there's one last step you're going to have to do. In Windows / IIS, $_SERVER['REQUEST_URI'] is blank. You need to use $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'] instead. If you don't, WP-Cache will happily cache your index.php file, but it will also think your /index.php/category/cheese/ page and your /index.php/2006/01/01/I-am-very-interesting/ page are the same as index.php.

In wp-cache-phase1.php (and also advance-cache.php) look for this line:

$key = md5(preg_replace('/#.*$/', '', $_SERVER['REQUEST_URI']) . wp_cache_get_cookies_values());

and change it to this:

$key = md5(preg_replace('/#.*$/', '', $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO']) . wp_cache_get_cookies_values());

By the way, one nice thing about step 6 above is that it also fixes a blank-page bug that some people have run into.

Finally, what if you want to use both WP-Cache and gzip? Here's how.

Supporting the blind – Accessible AJAX with unobtrusive Javascript

I posted earlier about how a federal judge has ruled that the ADA applies to web sites, and that a lawsuit against Target can go forward. I mentioned that it wasn't too hard to support the blind, and that through the mojo of unobtrusive Javascript, you can even make it work on AJAX-powered web2.0 sites that the kids are into these days. Some of you might scoff at the notion that it is easy or even possible, so I thought I would write a quick followup with some links to further information. Web Accessibility The W3C has a whole section about their guidelines. Here you can find guidelines, techniques, and the Section 508 rules. You can also Dive Into Accessability. Here you'll find tips arranged by specific disability. Accessible Javascript and AJAX AJAX, JavaScript and accessibility from Robert's Talk. This is a great page with real code examples of how you can employ a progressive enhancement strategy with your scripts. Digital Web Magazine has a good page about separating content from behavior. More good examples here. Many web developers have adopted the practice of separating content from presentation using CSS. You can also define a behavior layer using external .js includes. Ben Nolan has a Behavior script you can download. In addition to some helpful examples, you can download and use his framework to get started quickly.

Your four most important users are blind

If you are a web developer, and haven't heard of National Federation of the Blind v. Target, you will soon. Last week Federal Judge Marilyn Hall Patel ruled that retail companies can be sued if their websites are not accessible to the blind. The ruling allows the case to go forward and opens the door to Americans with Disabilities Act (ADA) lawsuits against other web sites as well-perhaps yours or your employer's. Web accessibility is one of the big, scary monsters that has been lurking under the bed for years - issues that undermine how a lot of people make web sites. Something many web developers and site designers don't know about, or don't want to think about. Now as scary as this ruling (and a possible future decision in favor of the National Federation of the Blind) might sound, this is actually a good thing. This is a win-win situation, because the your four most important users are blind, and you may have been ignoring them for years. You might not think you have any blind users, but you do. The four most important users of your site, who (hopefully) visit every single page on a regular basis, are Google, Yahoo, MSN and Ask. The techniques that make your site available to the blind are the same that make your site available to search engine spiders like Googlebot, and allow your site to show up on Google searches. Luckily, making your web page accessible is not that hard to do. If you write valid HTML or XHTML you’re almost done. Some of the things you need to avoid, like using .gif files for text instead of, well, text, actually make maintaining a web site easier in the long run. Using CSS for your presentation rather than deprecated FONT tags and layout tables will have productivity payoffs almost immediately. In fact, most difficulties in implementing it will be organizational problems - having a complicated internal process that requires huge lead times for any work, having such a small organization that any changes to the site are a significant cost, having tied yourself to some proprietary solution that spits out crappy HTML. What about web 2.0? A little bit trickier, but there is an answer: unobtrusive JavaScript. The HTML you serve to the client is valid, accessible code, with external JavaScript files that adds AJAX goodness to your page. It looks something like this: 1) Test for JavaScript and the XMLHttpRequest object. 2) Have an event setup function that adds onchange, onsubmit, and other calls to your page. 3) If a user without JS clicks a button, the page reloads and the content is given to them the old fashioned way. 4) If a user clicks the same button with JS on, the event is triggered, your AJAX functions are called, and updates can be made to the page with no reload. Writing relatively static or database-driven web sites to be accessible is not really an additional cost - in fact it will encourage good practices that will save time in the long run. Writing accessible AJAX will be a bit more difficult, but doing AJAX in the first place is still a bit of an experiment. It's not impossible, and it will also solve some of your search engine optimization problems. Of course, there are other blogs commenting on this, including a few like Eidelblog that disagree with any government-mandated accommodation. Do you think this is a positive step forward, or government interference? Post comments below.

What are you eating under there?

That one never gets old. Annie Mo's post about the appropriate body type for the people who are supposed to be helping you exercise has inspired me to share a few things. In the spirit of helping each other help ourselves to weight loss, there's a low-tech solution: a do-it-yourself diet tracker you can print out. In general, Lifehacker is a good place to go for web 2.0 weight loss and other cool toys. If you are a little too modern to want to use ink on dead trees, you can try Mealographer, a web site that lets you enter meals and find out the fat, calories, etc. that you have just thrown down your gullet. You can save meals and set goals to see if you are eating healthier over time. Mealographer even has a feature to suggest foods based on meals other users have entered. For some extra motivation: [youtube]aDDP__JDWPA[/youtube] Got a favorite tool you have been using? Post it in the comments below.