Cut 90% of your WordPress translations loading time

WordPress translations are compiled from human-readable PO-files into machine optimized MO-files, but still takes a lot of overhead to load. If you only could cache the translation load time, you would save a lot of page load time. We can easily cut 90% of our WordPress translations loading time.

According to my tests, you could actually save 90% of the load time, just by caching the results in a database-saved transient. If you add a proper persistent object-cache backed by Memcache, Redis, or php-apcu you should see a huge speed improvement on that again. I did a few tests here on the “default” textdomain, which showed a 90 % speed gain:

I did some more tests, with both plugins and themes, and they consistently showed a 90% speedup gain of the WordPress translations loading time.

You don’t have to worry about cache purging or using stale translations, as the function checks the file modification time of your translation files, before using the cached version.

The WordPress.org user nicofuma has added a Trac ticket 3 years ago, where it looks like everybody ended on an agreement of merging this into a future release, some 20 months ago. I have no idea why this isn’t in WordPress core yet, but if you want to use this yourself right now, you can add an mu-plugin with the following code from Per Søderlind:

6 Comments

  1. Hello Bjorn,

    I saw your comment on twitter that you preferred polylang pro above multilangualpress. I’m hesitating about which one to choose for woocommerce store, because multilangual does not synchronize the shopping cart or stock, but some peole had slower website because of polylang and in my case I will probably need polylang business pack. Now how could I use the above plugin with polylang for the benefit of performance?
    With kind regards,
    Amelia

Comments are closed.