~/swaraj.dev
Back to all posts
May 4, 20261 min read

Lazy‑Loading Native Modules to Shrink RN Startup Time

Load heavy native modules only when needed using dynamic import, cutting down initial bundle size and improving cold‑start performance in React Native apps.

performancereact-nativelazy-loading

Insight

React Native bundles all JavaScript, including native module wrappers, at startup. If a module like expo-location or a custom native bridge is only used in a few screens, loading it eagerly adds unnecessary weight to the initial bundle and delays the first render. By leveraging JavaScript's import() syntax you can defer loading until the feature is actually invoked, keeping the startup bundle lean and improving perceived performance.

Example

// Somewhere deep in a screen that needs location
import { useState } from 'react';

export function LocateButton() {
  const [location, setLocation] = useState(null);

  const requestLocation = async () => {
    const { getCurrentPositionAsync } = await import('expo-location');
    const pos = await getCurrentPositionAsync({ accuracy: 3 });
    setLocation(pos);
  };

  return <Button title="Get Location" onPress={requestLocation} />;
}

Takeaway

Wrap optional native APIs in import() calls and trigger them only when the user navigates to the related feature. This pattern reduces the initial JavaScript payload, shortens cold‑start times, and keeps your app responsive on low‑end devices.