In this official Firebase example it's described how to structure cloud functions to minimize cold start times.
The main idea seems to be the following in the index.ts file:
export const httpFn =
functions.https.onRequest(async (request, response) => {
await (await import('./fn/httpFn')).default(request, response)
})
In other words using await( await import()). This example is however in typescript. How would this look in node.js? I've found some examples. Eg. this one.
In there the index.js file has:
exports.helloWorld = require('./hello-world').helloWorld
And the individual function files look like:
const functions = require('firebase-functions')
exports.helloWorld = functions.https.onRequest((request, response) => {
const output = {
di: 'is cool',
}
response.send(output)
})
Is this the optimal method to minimize cold start time in node.js? Given I can't use "await import". Will this structure only load the necessary dependencies for each individual function? Or will it still load all dependencies across all required (imported) files?