Skip to main content

RAM Bundles and Inline Requires

Reduce your React Native app’s startup time by using RAM (Random Access Module) bundles and inline requires to load JavaScript code on-demand.

What are RAM Bundles?

RAM bundles split your JavaScript bundle into multiple files, allowing the app to load only the modules it needs at startup, deferring the rest until required.

Traditional Bundle

All code loads at startup, increasing time-to-interactive.

RAM Bundle

Only essential code loads at startup; modules load on-demand.

Benefits

  • Faster Startup: Only load essential modules initially
  • Reduced Memory: Lower initial memory footprint
  • Better User Experience: App becomes interactive sooner
  • Scalable: Benefits increase with app size

Enabling RAM Bundles

Android

Modify android/app/build.gradle:
Or configure in react.gradle:

iOS

Modify the bundle phase script in Xcode:
1

Open Xcode project

Open ios/YourApp.xcworkspace.
2

Edit build phase

Select your target > Build Phases > Bundle React Native code and images.
3

Update script

Change the script to use ram-bundle:
Alternatively, modify ios/YourApp/AppDelegate.mm:

Metro Configuration

Configure Metro bundler for RAM bundles in metro.config.js:

Inline Requires

Inline requires defer module loading until they’re actually needed.

Without Inline Requires

Everything loads immediately, even unused modules.

With Inline Requires

Modules load on-demand, reducing startup time.

Automatic Inline Requires

Babel plugin automatically converts imports to inline requires:
Update babel.config.js:
Now all non-top-level imports automatically become inline requires:
Combine inline requires with navigation:

React Navigation

React Navigation with getComponent

Conditional Requires

Load modules based on conditions:

Measuring Impact

Before Optimization

Monitor Bundle Size

Startup Time Profiling

Best Practices

Do Inline Require

  • Heavy screens/components
  • Rarely used utilities
  • Platform-specific code
  • Large third-party libraries
  • Analytics and tracking code

Don’t Inline Require

  • Core dependencies (React, React Native)
  • Frequently used components
  • Small utilities
  • Critical path code

Hermes + RAM Bundles

Combine Hermes bytecode with RAM bundles for maximum optimization:
Benefits:
  • Bytecode compilation is faster than JavaScript parsing
  • RAM bundles reduce initial load
  • Combined: significantly faster startup

Debugging RAM Bundles

Inspect Module Loading

Bundle Analyzer

Analyze your bundle composition:

Common Issues

Module Not Found

Ensure correct path in require:

Hot Reloading

Inline requires work with Fast Refresh:

Static Imports in Render

Avoid require in render method:

Performance Gains

Typical improvements with RAM bundles + inline requires:
  • Startup time: 20-40% faster
  • Initial memory: 15-30% lower
  • Time to interactive: 25-50% faster
Gains scale with app size and complexity.

Next Steps