Loading different js files for each platform for cordova projects



I’m using a couple of plugins that require a slightly different implementation for each platform, so I need to load a different JS file if it’s iOS than if it’s Android, for example.

Also, I need to load a cordova plugin or install it if it’s Android and not if it’s iOS or vice-versa, since the plugin uses the same JS interface, it would show conflicts if it’s installed.

So, I need to install and load a plugin if it’s Android or not install the plugin and load a different JS file if it’s iOS.

The plugins are being added with meteor add cordova:cordova-plugin-name@file///…path…/, and show up in the /myAPP/.meteor/cordova-plugins file.

Any tips will be greatly appreciated,



Normally the Cordova package itself handles the differences between platforms. You can’t find one which supports both or excludes itself? Which Cordova packages is this about?


Hello luc,

The interface works fine (without the need for calls to native) in Android but it doesn’t work with iOS and that’s why I need the plugin, but only in iOS (or android, it’s just an example) and I need a different JS file on the other platform.

Unfortunately, there is not another cordova plugin already made that provides this functionality, I know this because I already did my research, so I would have to fork it and do it myself, and that’s what this question is about.

I know how to disable the plugin in one platform, but not how to load a different JS file if it’s one platform or another.

The JS file I’m using has been included manually moving it to the project’s folder, it’s not loading the file in the www/file.js in the cordova plugin directory

Maybe I could wrap all of the code in the JS file I’m including in an if(platform == ‘android’) etc, that could work, the problem is that it will run after deviceReady event.


I think you can just load all JS but activate or even import what you need:

How to detect iOS / android:

Then you could do:

Can you be a bit more specific about what issue your code solves on iOS? Then it’s easier to recommend a more optimal solution.