Re: How to work with getScript() while "Include full jQuery in project code" setting On?

If your question is "how do I use a bookmarklet", you create a bookmark and then edit the bookmark and paste the bookmarklet code as the address/location.

I referenced the bookmarklets that tell you which methods are available in the different versions of jQuery on the page. If the method you want to use is listed in the "Optimizely jQuery", then you do not need to prefix the call with "window." If the method you want to use appears in the "not Optimizely jQuery", then you must use the "window." prefix so that Optimizely knows to use the page's version of jQuery instead of the Optimizely version.

For example, if I want to use .hide() or .show(), which do not exist in Optimizely's jQuery, I need to use like:

window.$('#someContent').hide()

If I try to do it without the prefix, nothing happens because the .hide() method does not exist in Optimizely's version of jQuery.

Adding "window." does not change the version of jQuery that is loaded on your page (this is contolled in your account settings). Adding "window." to a command only changes the scope of the command so that it can use the version of jQuery (and any plugins) loaded as part of your page.

Re: How to work with getScript() while "Include full jQuery in project code" setting On?

@nap0leon I use a project javascript setting "full jQuery snippet" and I believe you're wrong - in this mode, it's normal jQuery with all methods. Also if you look at the code I pasted - it references "window.optimizely.$". And I believe all it's methods work in browser console executed directly.

Re: How to work with getScript() while "Include full jQuery in project code" setting On?

@brushbill- Looks like you already figured it out, but for the sake of anyone else reading this thread later - the Optimizely version of jQuery are documented nicely in this writeup. The key takeaway is that Optimizely can deliver either:

1- no jQuery

2- a stripped down version of jQuery 1.6.4

3- the full version of jQuery 1.6.4 (notably, includes .hide() and .show())

More recent versions of jQuery (currently 1.11.3) contain additional methods that I use quite often, such as .on().

Typical build-cycle for an experiment is to develop code in your browser's console until you see the desired result. When you place this code into Optimizely, some times the code will not work and you won't know why. This is where the bookmarklets come in handy.

Since the code works in your console, there may be an issue of scope - any methods that show up in the "not Optimizely jQuery" bookmarklet need to be prefaced with "window." in order to run inside the variation's code block. All this code does is make the method call work.

Adding this prefix does not alter the version of jQuery that is loaded with your Optimizely library, nor does it alter any other scripts that your page loads (such as a full version of jQuery or plugins).

As for whether you can extend the optimizely scoped version of jQuery 1.6.4 with your plugin... that's a good question. Perhaps @Ehsan can shed some light on plugin-integration. I don't recall seeing that anywhere in the documentation. Presuming we even can do that, you would need to make sure that the plugin is compatible with version 1.6.4 and test whether it is available in the trimmed version (if not, you would need to switch to the full version of 1.6.4 in your account settings).

I'm actually trying to come up with a solution on how to relly only on one jQuery (be it Optimizely or page's jQuery) - so it seems that Optimizely jQuery is not enough, and native jQuery needs some strict implementation (right after opening <head>, followed immidietly by Optimizely JS snippet). Otherwise, if native jQuery is somewhere in the footer - it will slow everything down if not break it.