Is Cordova's JS loader.js?

Asked 2 years ago, Updated 2 years ago, 81 views

Sorry for the rudimentary question.
When I want to use cordova's js, should I use components loader.js?

cordova

2022-09-29 21:46

2 Answers

The cordova project generated by cordova create automatically loads cordova.js, so you don't need to write them directly in index.html or load them using loader.js.

The deviceready event is triggered when the API provided by cordova becomes available, so you can pass the callback function to deviceready to see if cordovaAPI is now available as follows:

 document.addEventListener('device ready', function(){
  // CordovaAPI is now available.
}, false);

To take advantage of non-cordova libraries (such as jQuery), write a script tag in index.html.

<script type="text/javascript" src="path/to/jquery.js">

In jQuery's ready and Cordova's devicesready, jQuery handles events better when they are ready, so you should receive devicesready first.

As your project grows in size, the program may become stuck depending on the library load order, so consider using require.js.


2022-09-29 21:46

When using Cordova, the JavaScript you specify is cordova.js.This may not be the case if you are using a framework wrapped around Cordova, for example, Ionic calls at least cordova.js.
(For example, <script src="cordova.js"></script>)

This cordova.js is not the type to download and deploy directly, such as jQuery, but is automatically generated in the folder of the platform when a corresponding platform is added, such as cordova platform add android.
For Android examples, it should be generated below $ app folder/platforms/android/platform_www.


2022-09-29 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.