From d0bb9b12051fa3540387a4c23d1f004b9d9a5a01 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 6 May 2018 23:08:42 +0200 Subject: querystring: lazy loaded PR-URL: https://github.com/nodejs/node/pull/20567 Reviewed-By: Gus Caplan Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- lib/url.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/url.js') diff --git a/lib/url.js b/lib/url.js index e4326e80b5..c517ba7ab3 100644 --- a/lib/url.js +++ b/lib/url.js @@ -94,7 +94,6 @@ const slashedProtocol = { 'file': true, 'file:': true }; -const querystring = require('querystring'); const { CHAR_SPACE, CHAR_TAB, @@ -133,6 +132,9 @@ const { CHAR_AT, } = require('internal/constants'); +// Lazy loaded for startup performance. +let querystring; + function urlParse(url, parseQueryString, slashesDenoteHost) { if (url instanceof Url) return url; @@ -233,6 +235,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { if (simplePath[2]) { this.search = simplePath[2]; if (parseQueryString) { + if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.search.slice(1)); } else { this.query = this.search.slice(1); @@ -422,6 +425,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { this.query = rest.slice(questionIdx + 1, hashIdx); } if (parseQueryString) { + if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.query); } } else if (parseQueryString) { @@ -584,8 +588,10 @@ Url.prototype.format = function format() { } } - if (this.query !== null && typeof this.query === 'object') + if (this.query !== null && typeof this.query === 'object') { + if (querystring === undefined) querystring = require('querystring'); query = querystring.stringify(this.query); + } var search = this.search || (query && ('?' + query)) || ''; -- cgit v1.2.3