Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native takes very long to load on device

Tags:

react-native

I've been developing a react-native app using the simulator for a while. On the simulator (iOS), the app loads very fast (on reload for eg). However, when I tried to load the app to the device, it spends between 1-3 minutes in the splash screen before loading into the app.

My project is fairly small, and has no extra resources other than the javascript. Looking at the documentation I couldn't find what might be the cause of the issue, though I suspect it has to do with the fact that it is not getting the JS from the packager local server.

What am I doing wrong?

(btw - react-native v0.31)

like image 583
AriehGlazer Avatar asked Sep 11 '16 08:09

AriehGlazer


People also ask

Why is React Native so slow?

Slow app launch is another issue of React Native apps. If your app opens too slowly, you probably have too many dependencies in your app and you're using slow components. Try to use fast, high-performance components and decrease the number of dependencies in your app.

Is React Native good for mobile?

React Native is great for mobile apps. It provides a slick, smooth and responsive user interface, while significantly reducing load time. It's also much faster and cheaper to build apps in React Native as opposed to building native ones, without the need to compromise on quality and functionality.

Is React Native still relevant in 2021?

React Native is not going to go away any time soon. JavaScript has been around since 1995 and it gives no signs of retiring any time soon — it was the most popular programming language on Stack Overflow's yearly survey for the past few years.


2 Answers

I ran into the same issue and discovered that it was because I was running my app on device in development mode. To get the performance you're looking for, you'll need to build and run the app in production or "release" mode. You can do this by passing in a --configuration option and setting it to Release using the React Native CLI:

$ react-native run-ios --configuration Release

If that doesn't do the trick, then you may need to build your app in "Release" mode from Xcode. To do that, navigate to your projects /ios directory and open the .xcodeproj file in Xcode. Choose your build target in the Toolbar. Scroll to the bottom and choose "Edit Scheme...". Then under Build Configuration, switch from "Debug" to "Release". Now build your app on your target device and it should be much more performant than before.

You can read more in the official React Native documentation under Running on Device: Building your app for production.

like image 116
Derek P. Collins Avatar answered Oct 26 '22 23:10

Derek P. Collins


For me the issue was related to the wifi network of my development machine. I was using WPA2 Enterprise auth to connect to wifi on my development machine. I found that if I used a wired connection to connect to my network or if I used another wifi connection that used a different form of auth then the delay went away. I think the delay is a network timeout.

like image 45
TALE Avatar answered Oct 27 '22 01:10

TALE