How to process a blog post

#Wordpress shortcodes are great. They allow a lot of flexibility in posts, and they are easy to create and manage. But they, in conjunction with everything else going on in wordpress, slow down a site. Every time a user views a post or page, the body must be searched for shortcodes, whether or not any exist, the code must be run and the codes replaced with whatever is required.

That's where caching plugins come in. They can store the pre-processed body of an article, so that it can be displayed much more quickly. There are limitations, as shortcodes account for much more that simple replacements. And then caches can be invalidated.

On this blog, the processing is more simple. But I still have to format and adjust some things, especially because I don't allow HTML when writing. Currently, I do all the processing at the time of publishing, so the body is fully prepared for a viewer. This has the downside that all operations must be reversible, in order to preserve editing functionality.

But recently, I thought of a better solution. Add a column to the database for the original, unprocessed version of the post. It's effectively like a built in cache. The unprocessed version is the "actual post" in wordpress terms. And the processed version is the cached version that gets displayed.

Currently, it is not possible for any of the processing to become invalidated by changes outside of the post, without modifying the function of the site. But in future, there would need to be a way to invalidate all posts and have them reprocessed from the raw version.

Posted 19 Aug 2020 by Brian