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

Question:

Often when templating in MODX you can use the [[!++site_url]] placeholder in the href attribute of a 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 this can cause headaches. Furthermore, because the site_url is a system setting, it is cached immediately upon cache refresh. There is very little performance boost to be had on page load from calling system settings cached, so the benefits outweigh the cost.

That’s all this time. Vive la MODX!