This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
optimization: Replace the url module with the querystring module #1825
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This optimization replaces all code in the webprotal that uses the url module with the querystring module and ensures consistent functionality. The result of this optimization is to reduce the total webprotal size from 478.4MB to 477.4MB.
The url module is built using the punycode and querystring modules, which are larger than the query string module. Webprotal uses the "url.parse().query" function of the url module to get the query type parameter of the address bar. However, this feature can be replaced by the "querystring.parse()" function in the smaller querystring module.
The reason is in lines 143 to 151 of url.js
this.query = querystring.parse(this.search.substr(1));
used the parse method in querystring. Both “url.parse().query” and "querystring.parse()" return an object, but "querystring.parse()" does not directly separate the domain name from the query parameter. You need to change it to
querystring.parse(window.location.href.slice(window.location.href.indexOf) ('?') +1));
will return the same object as "url.parse().query".The size of url.js, punycode.js, and querystring.js are 23KB, 18KB, and 6KB respectively. After the webpack is packaged, the size of all optimized JavaScript files will be reduced about 100KB. The specific changes are listed below:
login.bundle.js:937KB(before) 826KB(after)
hardwareDetail.bundle.js: 920KB(before) 810KB(after)
templateList.bundle.js:928KB(before) 818KB(after)
templateDetail.bundle.js:932KB(before) 822KB(after)
templateView.bundle.js:3.1MB(before) 3MB(after)
jobSubmit.bundle.js:16.3MB(before) 16.2MB(after)
submit.bundle.js: 1.6MB(before) 1.5MB(after)