I’m using a script that is based on jQuery, so I’m not enqueue-ing jQuery directly, but via passing it in the array of dependent scripts:
wp_enqueue_script("jquery-plugin-name",'http://hostname.il/blogname/wp-content/themes/twentyten/js/jquery-plugin-name.js', array('jquery'), '1');
This is loading jQuery v1.4.4, and it weighs 76kb, which seems very heavy, although the file looks compressed.
I have 2 questions:
- Is there I way in which I can make it load the latest version of jQuery?
- How can I make sure that the loaded file if minified?
That’s the size of the minified jQuery nowadays 🙂
You can load the latest from Google:
Please keep in mind that this can cause issues moving forward, as you are forcing WordPress to load a certain version of jQuery instead of the version bundled with it. There are plugins out there that may be better suited for your needs, like WP JQuery Plus, which make sure to load the same version number as WordPress does, but with the benefit of loading it from Google.
I have developed a plugin for this specific problem. This plugin doesn’t mess with WordPress jQuery as it is only loaded in the front-end. See: jQuery Manager for WordPress
Almost everybody uses the incorrect handle
WordPress actually uses the jquery-core handle, not jquery:
The correct way to do it
In my example below I use the official jQuery CDN at https://code.jquery.com I also use script_loader_tag so that I could add some CDN attributes.
You could use the following code:
Do not modify the version of jQuery enqueued by WordPress.
Just don’t do it. Core depends on a specific version. Themes and Plugins depend on a certain version. That certain version is the version bundled with a given version of WordPress.
If you need to perform script minification, compression, or concatenation, you can certainly do that (you can roll your own, or use a Plugin, such as W3 Total Cache, to do it for you.)
But as you can see: if you’re got a 46kB file, you’re already dealing with some combination of minification and compression.