MODX Quick Tip: Site URL - To Cache or Not To Cache?

Jul 12, 2013

Question:

Often when templating in MODX you can use the [[!++site_url]] placeholder in the href attribute of a <base> tag to make internal links relative. We know we should Always Be Caching, so should the placeholder be called like this: [[++site_url]]?

The Answer

No.

The Reasons

The biggest reason is portability. If you cache it, then every time you move the site to a different environment to make changes, or the hostname/domain changes for any other reason, the cache must be cleared for the site_url setting to have the correct value. During rapid development sprints, or when the site_url is in fact, dynamic, this can cause headaches. Furthermore, because the site_url is a system setting, it's value is available from the system_setting cache partition and there is very little performance boost to be had from calling it cached, anyways.

That's all this time. Vive la MODX!