Browser Cacheing

The Problem

If you go to a post on streetsblog.org, type in a beautifully written comment, fill in the rest of the fields including 5+7 is, um, 13 and hit “Post”, you get “Error: You have entered the wrong sum in the spam protection field…”  Damn!  So you hit Back and go to correct your error only to find that your comment is gone and you’ll have to type it all over again.  Sucks!

Tests

I have been told that this problem didn’t used to exist on streetsblog.org.  You would hit Back after such an error and still find your comment populating the Comment field.  So I repeated this simple test on different sites and browsers.  Here are the results:

Does the browser cache the comment text after an error?

gothamschools.org
no ie6
no ie7
no ie8
yes chrome
no ff 2.0.0.7 – xp
no ff – mac
yes safari – mac
streetsblog.org
n ie6
n ie7
n ie8
y chrome
n ff – xp
n ff – mac
y safari
streetfilms.org
n ie6
y ie7
y ie8
y chrome
y ff – xp
y ff – mac
y safari
cjyabraham.com
y ie6
y ie7
y ie8
y chrome
y ff – xp
y ff – mac
y safari

So it seems each browser has some kind of intelligence that tells it when to cache form content.  The top two sites are getting cached by fewer browsers than the bottom two.  One possible cause for this is the WordPress MobilePress plugin that only the top two run.  I set up a test instance of streetsblog.org at design.streetsblog.org and deactivated the MobilePress plugin and got these results:

design.streetsblog.org w/o mobilepress
n ie6
y ie7
y ie8
y chrome
y ff 2.0.0.7 – xp
y ff – mac
y safari

So it looks like that plugin is causing some browsers to stop cacheing a perfectly cacheable form entry.  Why is this?

I looked at the MobilePress code somewhat and suspected it might be the session_start(); line of the code and then spoke with Matt, one of the MobilePress developers, about this.  He suggested a few things which I tried but had no effect.  I even tried deleting this line completely but, still, the browsers would not cache the page.  So the problem must be somewhere deeper in the plugin.

Questions and Next Steps

This is where things stand for now.  I’m going to bounce this back to Matt and see if he has any other ideas.  Myself, I’m going to start stripping down the mobilepress plugin until I can find the line that might be causing this problem.

An alternative solution would be to get WordPress to provide error messages dynamically on the same page as the form.  This would be a good solution since cacheing form content in the browser is ultimately up to the browser so if we get things working in one version of Firefox, there’s no guarantee that they’ll work in the next.  The WordPress Cforms plugin can easily replace your comment form with an ajaxified form of its own that provides the errors inline.

And another solution would be to get rid of the math spam protection on streetsblog.org, which is the main cause for comment form errors there.  GothamSchools.org has been running without such a spam protection and has been having no problems with comment spam, due to akismet.

Afternoon Update

I performed two more tests on design.streetsblog.org by modifying the session_start(); line of code in MobilePress to two different options:

session_cache_limiter(‘public’);
session_start();

y ie6
y ie7
y ie8
y chrome
y ff 2.0.0.7 – xp
y ff – mac
y safari
if ( ! session_id()) @session_start();
y ie6
y ie7
n ie8
y chrome
n ff 2.0.0.7 – xp
n ff – mac
y safari

So both are an improvement but the left one is the best.  I ended up combining both edits because the second edit is going to be deployed in the new version of MobilePress.  Here is my final revision.

After I deployed this on all streetsblogs and gothamschools, I did another round of testing to find that, for some reason, things still aren’t being cached on the streetsblogs in ie8 and ie6.  The only reason I can think of for this is that the production server is configured differently than our test server.  Well, it’s running lighttpd instead of apache for one thing.  I think we can live with this for now.  All other tests pass.

One Response to “Browser Cacheing”

  1. Chris Abraham Says:

    Just an update on this. I retried the two things Matt had suggested, that is, adding “session_cache_limiter(‘public’);” to the top of the MobilePress code and replacing “session_start();” with “if ( ! session_id()) @session_start();” and this time I relaunched my browser in between tests. This time both edits worked at making the browser cache the comment.

Leave a Reply