medium.com 7 min read Original Source

Reducing App Bundle Size in React Native: Practical Strategies for Lighter Apps

When developing cross‑platform mobile apps with React Native, it’s easy for the final Android APK/AAB or iOS IPA to balloon in size. Large bundles take longer to download, consume more storage on users’ devices and can even affect performance. In competitive markets where bandwidth is limited and devices have limited storage, a bloated app can deter users from installing or updating. Understanding how to reduce your bundle size is therefore critical for both technical and non‑technical stakeholders. This article explores proven techniques to trim down your React Native app, explains why each strategy works and provides examples you can implement right away.

Why bundle size matters

Before diving into technical solutions, it’s worth understanding why size reduction is important:

  • Better user experience: Smaller apps download faster even on slow connections. In emerging markets where connectivity is limited, users may skip large apps altogether.
  • Reduced install footprint: The download size differs from the install size — the space an app occupies after installation. Minimising both helps users with devices that have limited storage.
  • Improved performance: Smaller bundles often load faster and consume less memory. Reducing unnecessary code and assets can lower memory usage and improve startup time.
  • App‑store compliance: Both Apple App Store and Google Play enforce size limits. Optimising your bundle helps meet these guidelines and avoids upload rejections.

1. Audit and minimise dependencies

Every external library you include increases your bundle size. Conduct regular dependency audits using tools such as Depcheck. Running npx depcheck will list unused packages and files you can safely remove. When choosing libraries, favour lightweight alternatives (e.g., date‑fns instead of Moment.js) and import only the specific functions you need rather than entire modules. Also, move development‑only packages (testing frameworks, storybook, etc.) to devDependencies so they don’t end up in your production bundle.

Example: Replacing heavy libraries

// Instead of importing the entire Moment.js library
// import moment from 'moment';

// Use a lightweight alternative like date‑fns
import { format, parseISO } from 'date-fns';
export function formatDate(dateString) {
  return format(parseISO(dateString), 'yyyy-MM-dd');
}
// Instead of importing the entire Moment.js library
// import moment from 'moment';

// Use a lightweight alternative like date‑fns
import { format, parseISO } from 'date-fns';
export function formatDate(dateString) {
  return format(parseISO(dateString), 'yyyy-MM-dd');
}

Switching to smaller libraries and importing only what you need significantly reduces the JavaScript portion of your bundle. Combine this with tree‑shaking (enabled by Metro/webpack) to remove unused code paths.

2. Enable Hermes for smaller JavaScript bundles

Hermes is a JavaScript engine designed specifically for React Native. It compiles JavaScript to bytecode ahead of time (AOT), which results in improved startup times, lower memory usage and smaller app size compared to running JavaScript on the default JavaScriptCore engine. Hermes is enabled by default in recent versions of React Native, but older projects may need manual configuration.

Enabling Hermes on Android

Edit android/app/build.gradle and set enableHermes to true:

// android/app/build.gradle
project.ext.react = [
    enableHermes: true  // enables Hermes; increases performance and reduces bundle size
]

// Then clean and rebuild your app
// cd android && ./gradlew clean && ./gradlew assembleRelease
// android/app/build.gradle
project.ext.react = [
    enableHermes: true  // enables Hermes; increases performance and reduces bundle size
]

// Then clean and rebuild your app
// cd android && ./gradlew clean && ./gradlew assembleRelease

Enabling Hermes on iOS

Open your Podfile and enable Hermes support:

:static
use_flipper!()
pod 'React', :path => '../node_modules/react-native', :subspecs => ['Core'], :modular_headers => true
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/React'
pod 'Hermes', :podspec => '../node_modules/react-native/ReactCommon/hermes-engine.podspec'
post_install do |installer|
react_native_post_install(installer)
end” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

# ios/Podfile
platform :ios, '12.0'

use_frameworks! :linkage => :static
use_flipper!()
pod 'React', :path => '../node_modules/react-native', :subspecs => ['Core'], :modular_headers => true
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/React'
pod 'Hermes', :podspec => '../node_modules/react-native/ReactCommon/hermes-engine.podspec'
post_install do |installer|
  react_native_post_install(installer)
end
# ios/Podfile
platform :ios, '12.0'

use_frameworks! :linkage => :static
use_flipper!()
pod 'React', :path => '../node_modules/react-native', :subspecs => ['Core'], :modular_headers => true
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/React'
pod 'Hermes', :podspec => '../node_modules/react-native/ReactCommon/hermes-engine.podspec'
post_install do |installer|
  react_native_post_install(installer)
end

After enabling Hermes, rebuild your project. You can verify Hermes is active by checking global.HermesInternal in your JavaScript code. When Hermes is enabled, the app’s JS bundle is compiled into bytecode, which reduces size and improves startup speed.

3. Shrink native code using Proguard/R8

Proguard (replaced by R8 in recent Android Gradle plugins) shrinks, optimises and obfuscates Java/Kotlin bytecode. It removes unused classes, methods and attributes, reducing the final APK size. Activate it by setting minifyEnabled true and including appropriate Proguard rules.

Enabling Proguard/R8

// android/app/build.gradle
android {
  buildTypes {
    release {
      shrinkResources true      // removes unused resources (images, strings, etc.)
      minifyEnabled true         // enables code shrinking, obfuscation and optimisation (R8)
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                    'proguard-rules.pro'
    }
  }
}
// android/app/build.gradle
android {
  buildTypes {
    release {
      shrinkResources true      // removes unused resources (images, strings, etc.)
      minifyEnabled true         // enables code shrinking, obfuscation and optimisation (R8)
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                    'proguard-rules.pro'
    }
  }
}

In proguard-rules.pro, include keep rules for React Native classes and your own Java/Kotlin code. For example:

-dontwarn com.facebook.react.**
-keep class com.facebook.react.** { *; }
-dontwarn okhttp3.**
-keep class okhttp3.** { *; }

// Add other keep rules for native modules or libraries you use
-dontwarn com.facebook.react.**
-keep class com.facebook.react.** { *; }
-dontwarn okhttp3.**
-keep class okhttp3.** { *; }

// Add other keep rules for native modules or libraries you use

R8 also performs resource shrinking (shrinkResources) and optimisation, which can dramatically reduce APK size if there are many unused resources. Test thoroughly after enabling R8; aggressive shrinking may remove code paths used by reflection.

4. Deliver device‑specific builds

a. Use Android App Bundles

The Google Play Android App Bundle (AAB) format includes all compiled code and resources but defers APK generation and signing to Google Play. When users download your app, the Play Store generates an optimised APK containing only the code and resources necessary for the user’s device configuration. This eliminates the need to ship large universal APKs and often results in significantly smaller downloads. To generate an AAB, run:

cd android && ./gradlew bundleRelease
cd android && ./gradlew bundleRelease

Upload the .aab file to Google Play. The Play Console will handle device‑specific splits automatically. According to Google, this approach typically reduces download size by as much as 20‑30 %.

b. Split APKs by CPU architecture

If you must distribute APKs outside of Google Play or support stores that don’t accept AABs, create separate APKs per architecture. Each ABI (e.g., armeabi‑v7a, arm64‑v8a) contains its own native libraries. Configuring the split ensures devices download only the relevant binary rather than a universal APK that bundles all architectures.

Add the following to android/app/build.gradle:

android {
  splits {
    abi {
      enable true
      reset()
      include 'armeabi-v7a', 'arm64-v8a'
      universalApk false  // Don’t create a universal APK
    }
  }
}

// Then build separate APKs
./gradlew assembleRelease
android {
  splits {
    abi {
      enable true
      reset()
      include 'armeabi-v7a', 'arm64-v8a'
      universalApk false  // Don’t create a universal APK
    }
  }
}

// Then build separate APKs
./gradlew assembleRelease

Upload each architecture‑specific APK to your distribution channel. Many developers prefer using App Bundles because Google Play automatically generates these splits.

5. Optimise images, fonts and other assets

Images and fonts can contribute heavily to app size. Optimise them by:

  • Compressing and resizing images: Compress PNGs and JPEGs. For Android, convert images to WebP, a modern format supported by Android that provides up to 30 % better compression.
  • Using vector icons: Replace multiple raster icons with vector icons (e.g., react-native-vector-icons) or the react-native-svg library. SVGs scale without increasing bundle size and avoid bundling multiple sizes of the same icon.
  • Managing fonts: Include only the weights and character sets you need. Large font families can add megabytes. Consider loading fonts dynamically from Google Fonts rather than bundling them in your app.

6. Code splitting and lazy loading

Loading all your components on startup increases the initial bundle size and delays the first render. React Native supports dynamic imports with React’s lazy and Suspense API. Code splitting divides your app into chunks that are loaded on demand, lowering the initial bundle size.

Example: Lazy loading a heavy screen

import('./screens/HeavyScreen'));

function AppNavigator() {
return (
<Suspense fallback={}>

);
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// A heavy screen component that shouldn’t load until needed
const HeavyScreen = React.lazy(() => import('./screens/HeavyScreen'));

function AppNavigator() {
  return (
    <Suspense fallback={<ActivityIndicator size="large" color="#000" />}>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Heavy" component={HeavyScreen} />
      </Stack.Navigator>
    </Suspense>
  );
}
// A heavy screen component that shouldn’t load until needed
const HeavyScreen = React.lazy(() => import('./screens/HeavyScreen'));

function AppNavigator() {
  return (
    <Suspense fallback={<ActivityIndicator size="large" color="#000" />}>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Heavy" component={HeavyScreen} />
      </Stack.Navigator>
    </Suspense>
  );
}

This pattern ensures the HeavyScreen bundle is only downloaded when the user navigates to it, reducing the initial download and startup time.

7. Remove console logs and unused code

Leaving console.log statements in production increases your bundle size and can leak sensitive information. Use babel-plugin-transform-remove-console to strip console statements during the build process. Similarly, remove dead code, debug functions and demo assets before building your release version.

8. Use a custom hook to load optional dependencies

Some third‑party modules (e.g., analytics libraries, rich‑text editors) are large but not always needed. You can write a custom hook that dynamically imports heavy libraries only when certain conditions are met — such as when a feature flag is enabled or when the user performs a specific action.

<button data-code="import { useEffect, useState } from 'react';

/**
* useDynamicModule
* Dynamically imports a module when condition is true and returns it.
* Falls back to null while loading.
*/
export function useDynamicModule(condition: boolean, importer: () => Promise): T | null {
const [module, setModule] = useState(null);
useEffect(() => {
let isMounted = true;
if (condition && module === null) {
importer().then((m) => {
if (isMounted) setModule(m.default);
});
}
return () => {
isMounted = false;
};
}, [condition]);
return module;
}
// Usage example
// Suppose your app includes a heavy chat module
const ChatScreen = () => {
const ChatModule = useDynamicModule(isChatEnabled, () => import('./modules/ChatModule'));
if (!ChatModule) {
return ;
}
return ;
};” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

import { useEffect, useState } from 'react';

/**
 * useDynamicModule
 * Dynamically imports a module when condition is true and returns it.
 * Falls back to null while loading.
 */
export function useDynamicModule<T>(condition: boolean, importer: () => Promise<{ default: T }>): T | null {
  const [module, setModule] = useState<T | null>(null);
  useEffect(() => {
    let isMounted = true;
    if (condition && module === null) {
      importer().then((m) => {
        if (isMounted) setModule(m.default);
      });
    }
    return () => {
      isMounted = false;
    };
  }, [condition]);
  return module;
}
// Usage example
// Suppose your app includes a heavy chat module
const ChatScreen = () => {
  const ChatModule = useDynamicModule(isChatEnabled, () => import('./modules/ChatModule'));
  if (!ChatModule) {
    return <Loading />;
  }
  return <ChatModule />;
};
import { useEffect, useState } from 'react';

/**
 * useDynamicModule
 * Dynamically imports a module when condition is true and returns it.
 * Falls back to null while loading.
 */
export function useDynamicModule<T>(condition: boolean, importer: () => Promise<{ default: T }>): T | null {
  const [module, setModule] = useState<T | null>(null);
  useEffect(() => {
    let isMounted = true;
    if (condition && module === null) {
      importer().then((m) => {
        if (isMounted) setModule(m.default);
      });
    }
    return () => {
      isMounted = false;
    };
  }, [condition]);
  return module;
}
// Usage example
// Suppose your app includes a heavy chat module
const ChatScreen = () => {
  const ChatModule = useDynamicModule(isChatEnabled, () => import('./modules/ChatModule'));
  if (!ChatModule) {
    return <Loading />;
  }
  return <ChatModule />;
};

This hook only loads the chat module when isChatEnabled is true. Such dynamic loading helps keep the initial bundle lean and avoids loading code that might never be used.

9. iOS‑specific optimisations

  • Use Bitcode (older versions): When building with Xcode, enabling Bitcode can reduce the final app size because Apple performs additional optimisation during App Store processing. However, as of Xcode 14 Apple has deprecated Bitcode; check the latest guidelines for your deployment target.
  • Enable Swift optimisations: Use -Osize and -whole-module-optimization flags in your Xcode build settings to reduce binary size.
  • Remove unused assets: iOS asset catalogs (.xcassets) should include only the images and icons your app uses.

Conclusion

Reducing your React Native app’s bundle size is an iterative process. Start by auditing dependencies and enabling Hermes to shrink the JavaScript bundle. Next, turn on Proguard/R8 and configure device‑specific builds via App Bundles or per‑ABI APKs. Optimise images, fonts and other assets, and adopt lazy loading to split large chunks of code. Remove debugging statements and use custom hooks to load optional modules only when needed. Each technique contributes incremental gains that collectively make a noticeable difference. A smaller app not only improves user experience but also aligns with store requirements and improves performance.

Developer checklist

  • Run npx depcheck and remove unused dependencies.
  • Replace heavy libraries with lightweight alternatives; import functions selectively.
  • Enable Hermes for both Android and iOS.
  • Activate Proguard/R8 with resource shrinking and proper keep rules.
  • Build and upload Android App Bundles or split APKs by architecture.
  • Compress images; convert to WebP; use vector icons and minimal fonts.
  • Implement lazy loading and dynamic imports to split code.
  • Strip console logs from production builds.
  • Test release builds thoroughly to ensure that code shrinking and splitting don’t break functionality.

By following this checklist and continuously monitoring your bundle size, your React Native app will stay lean, performant and ready for users across the world.

If you enjoyed this, follow React Native Journal for weekly tips on building faster, scalable React Native apps.

Level up your React Native skills with my Gumroad eBooks

Get the React Native for Web in 2025: One Codebase, All Platforms on Gumroad.

Get the Master React Native Styling and Layout with Flexbox — Your Ultimate Guide on Gumroad.