Quick Tip: Beware When Using the Slim Version of jQuery
In this quick tip I’m going to explain to you when you should and shouldn’t use the “slim version” of jQuery. For this tip I’ll assume you’re familiar with jQuery, or have heard of it at the very least.
jQuery vs. jQuery Slim
To use jQuery you would ordinarily go to https://jquery.com/download/ and grab one of the packages on offer. Currently the compressed production version of jQuery weighs in at 87Kb. This isn’t a huge amount, but you can make a further saving of 17Kb by opting for the compressed production slim version instead.
When you’re trying to optimize performance you’ll rightly take every saving you can, but here’s the catch: the slim version saves weight by excluding the ajax and effects modules.
The ajax module is probably the lesser-used of the two. It contains functions and methods which allow us to load data without needing a page refresh. The effects module, however, is more likely to feature in your websites; it contains functions and methods for commonly-used animations.
animate() for example,
show() and so on. If you’ve ever used jQuery, the chances are you’ve used one of these methods.
So that covers the essential message here: if you need any of the methods or functions found in the ajax or effects modules of jQuery, use the full version. If not, you’ll make a small saving by using the slim version instead.
Now, finally, to the main reason behind this quick tip! It’s worth noting that Bootstrap 4 (the latest version of the framework) uses the slim version of jQuery. Therefore if you’re building with Bootstrap and you plan on adding any extra interactivity which relies on ajax or effects, you’ll have to load the full jQuery library instead.
I hope that saves you some headaches!