In this article we will explain the differences between convert._$ and convert.$
CONVERT._$ - use it inside Code Editor
convert._$ is a jQuery reference modified in such a way so that the variation code can be executed multiple times while the page is still loading. We execute the code every 50 ms until there's nothing left inside the code that seems to need processing, or until DOM ready is hit. Let's have an example to understand how it works:
convert._$("a.login").text("Login here");
convert._$("a.loginFooter").text("Login");
We would execute this code immediately as our script finishes loading. It's very likely that is at the very beginning of the page load when not all the page was rendered yet. Let's suppose, at the moment of the first run, the a.login is available but a.loginFooter is not available. The effect of the code would be that the text of the a.login link would be changed to "Login here".
After another 50 ms, we run the code again since there's one element that was not found. This time, the a.loginFooter is available and its text is changed to"Login"; the a.login is not changed again since it was changed before.
As can be noticed, we wrapped the jQuery library into our own convert._$ function so that we can intercept the elements look-ups and know when the code "finished executing".
This allows us to run the code and change the elements without waiting for the DOM ready (which would ensure everything was loaded) since that takes time and users would experience a flickering effect (old version visible and then swapped with the new version).
CONVERT.$ - use it inside Custom Javascript
convert.$ exposes the unmodified version of Jquery for you to use, without the benefits of the modified version.
Judging from this, it sounds like any code inside the "Custom JavaScript" section only runs once, but code inside the "Code Editor" runs every 50ms. Is this correct?
That is correct, Robert. The code in the Code Editor runs every 50ms up until document ready, and then just once more after that.
I believe the title of the article needs to be updated to include a period inside `convert_$`. I had a more difficult time finding the article because of this.
Brandon, I added the period to the title. Thanks for the suggestion.
Thanks, George. The period's still in the wrong place though.. it should be convert._$ vs. convert.$
Brandon, corrected.
which approach will load faster?
convert._$("a.login").text("Login here");
or
convert.$("a.login").text("Login here");