The JavaScript library jQuery offers numerous modules for extending functionality. However, many of these are not needed in every project, which can unnecessarily prolong loading times. To improve performance, unnecessary modules can be removed using the JavaScript task runner Grunt. By excluding unnecessary modules, jQuery 3.6.0.min can be reduced by around 30%, which reduces both the website’s loading time and the memory usage in the browser.
Currently, jQuery allows the exclusion of the following modules:
- Ajax: Enables data retrieval without a full page reload.
- Deprecated: Contains functions that will be removed in future versions.
- CSS: Supports manipulation of CSS properties.
- Event Alias: Provides shortcuts for handling DOM events.
- Dimensions: Allows retrieval of element dimensions (width, height).
- Effects: Includes visual effects like fade in and fade out.
- Offset: Calculates the position of an element relative to the document.
$ mkdir jquery-build
$ cd jquery-build/
$ git clone https://github.com/jquery/jquery.git
$ cd jquery/
$ git checkout <branch>
Switching jQuery versions is possible later with:
$ git switch [<options>] <branch>
$ npm install
If npm install
hangs at idealTree:lib: sill idealTree buildDeps
, this may be due to issues with IPv6. In this case, disabling IPv6 may resolve the issue. The following commands can help:
$ npm cache clear --force
$ npm config set registry http://registry.npmjs.org/
# sysctl -w net.ipv6.conf.all.disable_ipv6=1
# sysctl -w net.ipv6.conf.default.disable_ipv6=1
For example, to remove the Ajax module, Grunt is invoked as follows:
$ grunt custom:-ajax
Multiple modules can be removed by separating them with commas:
$ grunt custom:-ajax,-effects,-css,-deprecated,-event-alias,-dimensions,-effects,-offset