Add jQuery via a plugin to code with jQuery in custom Optimize code.
If you’re writing JavaScript in Optimize and prefer jQuery over vanilla JS, you can request to enable the jQuery plugin. This lets you use the $ symbol in your code — but keep in mind that enabling jQuery can impact page performance.
When JavaScript can be used in Optimize
- Code-based variations — includes supporting preconditions or variation logic
- Global code — runs for all optimizations and variations
- Optimization code — audience logic, custom page definitions, or event logic
Should you enable jQuery?
Most of the time, you don’t need it. Vanilla JavaScript can usually do everything you need — and skipping jQuery cuts ~30 KB from the snippet. Like any script, the Optimize snippet adds to your page’s load. The smaller it is, the faster your site loads.
Don't enable jQuery if:
- You’re not writing JavaScript in Optimize
- You’re comfortable writing in vanilla JavaScript
- Your site already includes jQuery and you plan to expose that version to Optimize
Enable jQuery if:
- You prefer working with it and aren’t concerned about the performance impact
If your site already has jQuery
If your site already includes jQuery, you can expose your existing version on the window object (e.g., window.jQuery = jQuery) so it’s available in the dashboard’s global code. This avoids loading a second copy of jQuery — which saves performance — and still works, since Optimize won’t conflict with other versions on the page.
If you go this route, make sure your version of jQuery loads before the Optimize snippet. If it’s missing or delayed, your global code might not work as expected. And if you switch to the Optimize plugin later, it may not match your version.
jQuery plugin details
- Plugin version — uses jQuery 3.6.3 (may update for minor/patch versions)
- Scope — code runs in an isolated scope to avoid leaking
- Compatibility — doesn’t conflict with other versions of jQuery
How to enable or disable the plugin
Submit a support request to enable or disable the jQuery plugin. If you’re disabling it, make sure no Optimize code (e.g., global, audience, page, or variation code) still relies on jQuery.
In your support request:
- To enable — mention that you're writing JavaScript and want to use jQuery
- To disable — confirm that you’ve removed jQuery from all custom code and no longer need it