Keystone-classic: Why node require in function level in cloudinary.js

Created on 1 May 2018  路  1Comment  路  Source: keystonejs/keystone-classic

I was just going through the /admin/server/api/cloudinary.js file and noticed it's importing the cloudinary node library at the function level -- in three separate functions.

Is there a specific reason it's doing this as against importing it at the package/module level ? Seeing the require action is synchronous.

see -

question

Most helpful comment

From memory, we went through a whole effort to reduce the initial boot time by only requiring packages you were actually using (when they were first used).

require is sync but cached, so you only pay the cost of this once the first time the API route is hit. It's a trade-off with doing the require when Keystone is first required, which would include users that aren't even using coudinary.

>All comments

From memory, we went through a whole effort to reduce the initial boot time by only requiring packages you were actually using (when they were first used).

require is sync but cached, so you only pay the cost of this once the first time the API route is hit. It's a trade-off with doing the require when Keystone is first required, which would include users that aren't even using coudinary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schybo picture schybo  路  3Comments

calebmcelroy picture calebmcelroy  路  3Comments

jacqueslareau picture jacqueslareau  路  5Comments

zhdan88vadim picture zhdan88vadim  路  5Comments

sorryididntmeantto picture sorryididntmeantto  路  3Comments