[ 
https://issues.apache.org/jira/browse/CB-5671?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13922611#comment-13922611
 ] 

Jon Whitlock commented on CB-5671:
----------------------------------

Thanks for the movement on this folks.

agrieve: "do you have any suggestion on how to make this work better with 
require.js? E.g. does it support setting values via the <script> url? e.g.: 
<script src="cordova.js#autoload=false">"

There will be no script tag, that is the problem, so findCordovaPath() will 
always fail (I hack it to return our NAMESPACE.Config.baseUrl + 
"/path/to/vendor_scripts/").  IMO it's much simpler and not unreasonable to 
make it a config option.

The only script tag is going to be the front loading JS (whether require.js or 
sth else), it will then dynamically load the remaining JS files async and rely 
on deferreds and/or promises (I assume) internally to manage dependencies as 
Modules get loaded.

Cordova does this internally IIRC, but seemingly requiring a SCRIPT tag means 
it won't play nicely with other dynamic loading JS frameworks that use AMD (of 
which there are many).

This may be informative;
http://requirejs.org/docs/why.html
http://requirejs.org/docs/whyamd.html

Cheers,
jon

> facilitate dynamic loading of cordova plugins
> ---------------------------------------------
>
>                 Key: CB-5671
>                 URL: https://issues.apache.org/jira/browse/CB-5671
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: CordovaJS
>    Affects Versions: 3.2.0
>         Environment: any
>            Reporter: Jon Whitlock
>            Assignee: Andrew Grieve
>              Labels: javascript
>         Attachments: Screen Shot 2014-03-06 at 8.49.27 AM.png
>
>
> Problem: Cordova expects resources to be loaded off the device filesystem.
> 1) On iOS this is very risky due to the turnaround time pushing hotfixes 
> through the App store.
> 2) In complex JS applications one needs to use a loader like require.js to 
> manage async loading (especially on mobile) & module dependancy management 
> (as cordova does internally).
> 3) When integrating with many 3rd-party services like auth/"social login" one 
> needs to have a public-facing page to call back to.
> Use case: We have a bunch of prereqs before cordova.js loads, so we have to 
> load cordova.js using require.js.  However to show localised error messages 
> we need the preferred language from the device to know which language to show 
> messaging in, so we need cordova loaded as part of auth prerequisites.
> Problematic Assumptions:
> a) findCordovaPath() assumes a script tag in the document loaded cordova.js 
> -- not the case with require.js or similar.
> b) injectPluginScript() assumes that cordova_plugins.js is in the same dir as 
> cordova.js
> So using plugins & dynamically loading Cordova is terminal, unless I hack 
> findCordovaPath() to return (in our case) the path where cordova.js is to be 
> found -- which is defined in a JS configuration file.
> I think it would be more robust to define the location of those file(s) in a 
> config file somewhere -- which could also facilitate dynamic loading of 
> cordova.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to