Marketpath CMS Developer Tutorial Series

Javascript

Last Updated 3/6/2018

Javascript is essential to dynamic websites. Here's what you as a developer need to know about javascript in Marketpath CMS.

All javascript is served over the CDN. While this would normally cause a significant delay between when you update a file and when it is available on the website, we have added a cache busting mechanism that ensures that users will always get your latest javascript updates as soon as they are published.

As a result, every URL for a javascript file on your site ends with a question mark followed by a series of numbers. If you need to reference that javascript file somewhere else (eg: another site), you should copy the full URL excluding the question mark and anything following it (so http://domain.com/path/to/file.js?123456789 becomes http://domain.com/path/to/file.js).

The CDN is a helpful tool to make your website fast, but there are other tools that we have built into our templating engine that can also improve page load performance. The most notable is the ability to easily load scripts asychronously and defer their execution to prevent parser blocking. Sound complicated? It's actually much simpler than it sounds, you just have to be careful how you use it.

To use this feature, you simply have to include the "async" and "defer" properties when you include the javascript using the {% add_javascript %} tag. Just be careful how you use this - if another script relies on functionality in this script you may not be able to take advantage of async and deferred scripts without experiencing some odd bugs. Also, if the same script is included multiple times with different options you could see unexpected behavior.

The obviously missing feature regarding javascript is the ability to bundle javascript files together to reduce the number of resource requests. Similarly, we do not offer any javascript code minification to reduce filesize. Currently, if you want to bundle or minify javascript files, you will have to use an external tool and copy the result into the CMS. We are considering solutions to offer this as a core part of Marketpath CMS in the future.

---- End of Lesson ----

Question? Correction?

Let's work together to make our documentation as helpful as possible.

What is your name? 
What is your email address? 
Feedback: