jQuery is surely the most well liked JavaScript library. Nearly every internet website online on the planet uses it. As a result of its same old use, jQuery comprises functionalities to cover every possible state of affairs.
Alternatively, when working on a simple internet website online, we might most likely best use a few of the ones functions. It’ll be additional setting pleasant to run best the vital functions and exclude the unused ones. We will exclude certain jQuery modules that aren’t sought after for our mission. Let’s uncover how to try this.
Getting Started
First, we want to arrange crucial apparatus for the obligation. The ones apparatus include Git, Grunt, and Node.js. Will have to you’re using macOS, the most simple technique to arrange the ones apparatus is right through the macOS package deal deal manager, Homebrew.
Setting up Homebrew
Open your Terminal and execute the following command to position in Homebrew. With Homebrew, putting in place the other apparatus becomes simpler.
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/transfer)"
Setting up Git
Once Homebrew is installed, execute the command beneath to position in Git.
brew arrange git
Setting up Node.js
Use the following command to position in Node.js:
brew arrange node
Setting up Grunt
In the end, arrange Grunt by the use of running the command beneath:
npm arrange -g grunt-cli
For House home windows consumers, there’s a comparable package deal deal manager named Chocolatey. You’ll have the ability to use it to position within the aforementioned packages in a similar manner.
Building jQuery
At present, jQuery we could within the exclusion of the following modules:
| Module | Command | Description |
| Ajax | -ajax |
This refers to the jQuery AJAX API, which comprises jQuery.ajax(), jQuery.get(), and the .load() function. |
| CSS | -css |
This pertains to functions from the jQuery CSS Class, at the side of .addClass(), .css(), and .hasClass(). |
| Deprecated | -deprecated |
This refers to the deprecated modules or functions. |
| Match Alias | -event-alias |
This pertains to occasion purposes very similar to .click on on(), .focal point(), and .hover(). |
| Dimensions | -dimensions |
This relates to the purposes for atmosphere CSS dimensions, at the side of .top(), .innerHeight(), and .innerWidth(). |
| Effects | -effects |
This refers to functions that follow animation effects, very similar to .slideToggle(), .animate(), and .fadeIn(). |
| Offset | -offset |
This pertains to functions that retrieve coordinates and position, at the side of .offset() and .position(). |
Quicker than customizing jQuery, we want to clone it from the GitHub repository. Execute the following command inside the Terminal:
git clone git://github.com/jquery/jquery.git
A brand spanking new folder named jquery it is going to be created to your shopper list. Navigate to this list with the command:
cd jquery
Next, arrange the Node dependency modules required for our mission:
npm arrange
Then, assemble jQuery by the use of simply executing the Grunt command:
grunt
If a good fortune, the following document it is going to be displayed:


As indicated inside the document, our jQuery is stored inside the dist/ folder. At this stage, our jQuery comprises all functionalities, resulting in a size of 265kb. The minified fashion is 83kb.


Module Removal
If you wish to remove the Effects module from jQuery, execute the following command:
grunt custom designed:-effects
Upon checking the file size all over again, you’ll comprehend it has diminished to 246kb.


To exclude a few modules, file every module separated by the use of a comma, like so:
grunt custom designed:-effects,-ajax,-deprecated
Except a few modules will further reduce the jQuery file size. In this instance, it’s been diminished to easily 207kb.
Concluding Concepts
jQuery facilitates easy DOM manipulation, then again its size, exceeding 200kb, would most likely impact your internet website online’s potency. By way of casting off useless jQuery modules, your script will surely run additional effectively and faster. We hope this tip proves truly helpful for your upcoming projects.
The post The way to Take away Pointless jQuery Modules appeared first on Hongkiat.
Supply: https://www.hongkiat.com/blog/jquery-remove-modules/


0 Comments