Prepare Command Performance in Cordova 7.x

April 13th 2018 Cordova Ionic 2/3

After we upgraded the Cordova version on our build server from 6.5.0 to 7.1.0, we noticed a large increase in build time for our project. By looking at detailed build times, we could attribute all of it to a single command: cordova prepare.

Based on the Cordova 7.0.0 release notes, the most probable reason for this was the following change:

Fetch is now the default method for fetching platforms. Fetch uses your system npm to npm install modules into your project. The --fetch flag is no longer required. Use the --nofetch flag to revert to pre-Cordova@7.0 behavior (npm install is not used to fetch modules).

Knowing about performance optimizations in NPM 5, our first instinct was to check the NPM version on the build server. However, we were already at NPM 5.x, hence we couldn't gain any performance there.

The only remaining logical explanation was that the new fetch method for fetching platforms (and plugins as well) was the culprit. The question was, how to disable it for the cordova prepare command. Unlike the other commands, prepare doesn't have a --nofetch option listed in the documentation. We tried using it any way, with success: cordova prepare --nofetch was just as quick as cordova prepare was in Cordova 6.5.0.

Here are some measurements using Measure-Command { cordova prepare | Out-Host } in PowerShell for a sample project with 2 platforms and 15 plugins, to put the above text into perspective:

Cordova NPM Command Time
6.5.0 5.7.1 cordova prepare 34 s
7.1.0 5.7.1 cordova prepare --nofetch 35 s
7.1.0 5.7.1 cordova prepare 397 s
7.1.0 4.6.1 cordova prepare 436 s

We're definitely sticking with cordova prepare --nofetch for Cordova 7.1.0. Not sure what will happen when we upgrade to Cordova 8.x (where support for nofetch has been removed). Currently we're not even considering it any way, because too many existing plugins don't work with it due to an internal module name change.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Creative Commons License