Apache Cordova is a framework that lets you build mobile applications using HTML5, CSS and Javascript for different mobile platforms. But because the applications you build with this framework live in a layer on the top of the native development tools of the targeted platform, they're slower than equivalent applications that are written using the native development tools. As is mentioned here:

However, the use of Web-based technologies leads some Apache Cordova applications to run slower than native applications with similar functionality.[27] Adobe Systems warns that applications may be rejected by Apple for being too slow or not feeling "native" enough (having appearance and functionality consistent with what users have come to expect on the platform). This can be an issue for some Apache Cordova applications.d

So it seems a good option if you could use some native code in a Cordova application. One way of doing this seems to be devloping a plugin. But again there is a catch(from the last link):

All the main Cordova API features are implemented as plugins

So any plugin you devlop, will have the same problem as the equivalent code in Cordova.
So, is there any way to mix Cordova with some native code that doesn't make the native code as slow as the part built using Cordova?
Thanks

Dani AI

Generated

Short answer: yes — native code can run at full native speed alongside a Cordova-based UI, but it only helps the pieces moved out of the WebView. The practical pattern is to keep cross-platform UI/logic in the web layer and push CPU-, I/O- or GPU-heavy work into native modules that run on native threads and return results via callbacks. This preserves the "write once" benefit mentioned while avoiding the main bottlenecks called out by .

Concrete pointers and examples

  • Move heavy work (image processing, cryptography, large JSON parsing, realtime audio/graphics) into native code and expose it through a Cordova plugin. Make sure that native work runs off the main/UI thread and that results are sent back via the plugin callback. Batch data and minimize JS/native round trips.
  • For shared logic between Android and iOS, implement the core in portable C/C++ (NDK / Objective-C++), then call it from each platform plugin to avoid duplicated algorithms.
  • Native UI: if the UI must feel fully native or requires GPU acceleration, present a native view (or a native surface such as OpenGL/Metal) from the plugin rather than trying to force complex UI into the WebView.

Example snippets (minimal skeletons)

JS caller:

cordova.exec(success, error, "HeavyPlugin", "run", [params]);

Android (CordovaPlugin using thread pool):

public boolean execute(String action, JSONArray args, CallbackContext cb) {
  if ("run".equals(action)) {
    cordova.getThreadPool().execute(new Runnable() {
      public void run() {
        int r = nativeHeavy(args.optInt(0));
        cb.success(r);
      }
    });
    return true;
  }
  return false;
}

iOS (Objective-C plugin, background queue):

- (void)run:(CDVInvokedUrlCommand*)cmd {
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    int r = doHeavyWork();
    CDVPluginResult* pr = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:r];
    [self.commandDelegate sendPluginResult:pr callbackId:cmd.callbackId];
  });
}

Troubleshooting and best practices

  • Profile first (Chrome remote debug for the WebView, Android Profiler, Xcode Instruments) to find the real hotspot.
  • Avoid frequent small JS/native calls; batch work and send compact results (use files or binary buffers for large data).
  • Be thread-safe and watch memory: native speed gains can be lost to poor marshaling or leaks.
  • If most of the app must behave and look native, consider a different architecture (React Native / Flutter) rather than forcing complex UI through a WebView.

Start by implementing one plugin for the single biggest hotspot, measure the improvement, and iterate from there.

Recommended Answers

All 3 Replies

I have to guess the issue is speed. If speed is the issue, create your app natively with Android Studio. If you want a web app, you go that way if that's your goal.

In short, pick your goals, find tools, go at it.

Well...yeah...but the good thing about using cordova is that you can build applications for different platforms using the same language. Of course if you use native code you should write in different languages for those portions but at least you write less duplicated code.

Ahh, the old "write once, run everywhere" idea. If that's the goal, you do give up platform, machine specific enhancements. I don't want to cover this old ground but want to encourage you to pick your goals and run towards them FAST before someone else gets there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.