Don’t worry though—with a few optimizations, NativeScript apps can startup fast enough for the overwhelming majority of app use cases. This article is a straight-to-the-point list of steps you can take to make sure your NativeScript apps start up as fast as possible.
NOTE: Jump to the summary if you want an explanation-free list of commands to run.
Using UglifyJS is easy too. To use UglifyJS as part of your NativeScript builds, all you need to do is add a
--env.uglify flag to the scripts you ran earlier. That is, run one of the following commands.
tns run android --env.uglify
tns run ios --env.uglify
If you open your
bundle.js files, you should now see compressed code that looks something like this.
The more code you have, the more of a difference the UglifyJS optimization will make. Here’s what the NativeScript Groceries sample looks like with Uglify added to the webpack build process.
In NativeScript we’re integrated this process directly within our webpack build process; therefore, running a build with V8 heap snapshots enabled is as simple as adding a
--env.snapshot flag to the previous step.
tns run android --env.uglify --env.snapshot
Note: Heap snapshots are a feature of V8 and you can only use this feature as part of your NativeScript Android builds. A similar feature is not available for NativeScript iOS builds.
NOTE: For a far more technical explanation of how V8 heap snapshots work in NativeScript, and how you can configure and optimize the snapshots, check out this article on the NativeScript blog.
By enabling webpack, using UglifyJS, and performing V8 heap snapshot builds, you have the ability to greatly improve the startup times of your NativeScript applications. As a reference, here is a brief summary of the commands you need to run to enable all optimizations.
1) Run on iOS with, UglifyJS, and Angular Ahead-of-Time enabled.
tns run ios --env.uglify --env.aot
2) Run on Android with, UglifyJS, Angular Ahead-of-Time (if using Angular), and V8 heap snapshot builds enabled.
tns run android --env.uglify --env.aot --env.snapshot