JavaScript: Loading jQuery on Demand
javascript, jquery
Solution
Just add a script tag for jQuery when you need it:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://www.example.com/jquery.js';
document.body.appendChild(script);
Problem
What is the most lightweight way to include the jQuery lib into a page dynamically? I'm working on a page where sometimes it runs a few custom scripts (10 lines) and other times the entire jquery is also needed.