Skip to content

Instantly share code, notes, and snippets.

@grittymindy
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grittymindy/864a775911554c44e6d6 to your computer and use it in GitHub Desktop.
Save grittymindy/864a775911554c44e6d6 to your computer and use it in GitHub Desktop.
react-native-hot-reload-proposal

##The basic proposal is:

  1. pack the js bundle within the app itself
  2. Each time you app is lauched, try to check with your server if your local js bundle need to be updated. If so, download the latest js bundle from your server, and save it into the sandbox. Say the destination path is DIR_FOR_JS.
  3. Your code loading js files should be like this:
    if(file exists in DIR_FOR_JS)
        load the file from DIR_FOR_JS
    else 
        load the file packed in your app

Although ReactNative supports loading online bundle, it's unacceptable to fetch the js files from server everty time. It is such a waste of data traffic and is not user-friendly when the network is poor.

Tips: There have been changes and reverts in github/facebook/react-native. To make sure that your version of RN supports loading js files from sandbox, check that the following codes are gone(in RCTJavaScriptLoader.m)

-  if ([scriptURL isFileURL]) {
-    NSString *bundlePath = [[NSBundle bundleForClass:[self class]] resourcePath];
-    NSString *localPath = [scriptURL.absoluteString substringFromIndex:@"file://".length];
-
-    if (![localPath hasPrefix:bundlePath]) {
-      NSString *absolutePath = [NSString stringWithFormat:@"%@/%@", bundlePath, localPath];
-      scriptURL = [NSURL fileURLWithPath:absolutePath];
-    }
-  }
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment