Implementing run-time versioning for Elements

Implementing run-time versioning for Elements

One of the benefits of MODX Revolution, is the simplistic methods required to establish run-time configurations.

Posted on March 24, 2012 at 13:11:00
Tags: Caching
Words: 575
Level: Advanced
Dependencies: None

Using System Settings

<script type="text/javascript" src="//[[++jquery_version:default=`1.7.1`]]/jquery.min.js"></script>
<script type="text/javascript" src="//[[++jquerytools_version:default=`1.2.6`]]/all/"></script>


[[++jquery_load:eq=`0`:then=``:else=`DO SOMETHING`]]
[[++jquerytools_load:eq=`0`:then=``:else=`DO SOMETHING`]]
<script type="text/javascript"


<script type="text/javascript" src="//">
<script type="text/javascript" src="//">


As you may have noticed, the jQuery version which was placed in the page was 1.7.2 and not the default 1.7.1 which was the "current" version when the site went live. This is due to existence of a System Setting which is used to override the default value.

Techniques such as this, allows a single Chunk to be used across multiple Templates and/or Resources in order to update various sections of the site, while leaving others set to the default value.

Most applications would simply place this in the header of a Template and allow the inclusion of the respective library to be managed site-wide - wherever the Template is in use.

Other applications may have very little need of the jQuery library, and therefore the inclusion of a Chunk on those pages may prove more beneficial.

Using a simple Chunk

<script type="text/javascript" src="//[[+jquery_version:default=`1.7.1`]]/jquery.min.js"></script>
<script type="text/javascript" src="//[[+jquerytools_version:default=`1.2.6`]]/all/"></script>


As this method may be considered more premeditated, the check for it being "desired" in the current page has been removed.

Chunk Call - jQuery Version


Chunk Output

<script type="text/javascript" src="//">
<script type="text/javascript" src="//">

Chunk Call- both changed


Chunk Output

<script type="text/javascript" src="//">
<script type="text/javascript" src="//">

Final Comments

These techniques can be used in a wide array of application, such as layout, targeted css, SEO, images, etc. In many situations similar implementations are the reason the page source changes upon every load. Experiment and see what you can come up with.

Website development platform combining security, power, and innovation.