Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15348] Android: 'require' a remotely-downloaded JavaScript module

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionWon't Fix
Resolution Date2013-10-07T16:04:39.000+0000
Affected Version/sRelease 3.1.1, Release 3.1.2, Release 3.1.3
Fix Version/sn/a
ComponentsAndroid
LabelssupportTeam
ReporterRupesh Sharma
AssigneeMatt Langston
Created2013-09-26T10:28:37.000+0000
Updated2017-03-22T21:37:43.000+0000

Description

Description

I need to be able to 'require' a javascript module from outside the resource directory. For example at first need to download myModule.js and use the code in this newly downloaded file (to applicationDataDirectory) if it exist.

Example

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});

var remoteInclude = function () {
    var url = "https://dl.dropboxusercontent.com/u/72777663/sayHello.js";
 
    var c = Titanium.Network.createHTTPClient();
    c.setTimeout(10000);
    c.onload = onSuccess;
    function onSuccess()
        {
            var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'sayHello.js');
            f.write(c.responseData);
            var myModule = require(Ti.Filesystem.applicationDataDirectory+'sayHello');
myModule.sayHello('Kevin');
        }
 
    c.ondatastream = function(e)
        {
        Ti.API.info('Progress : '+e.progress);
            
        };
    c.onerror = function(e)
        {
            Ti.API.info('XHR Error ' + e.error);
        };
    c.open('GET', url);
 
    c.send();
 
};

var but=Titanium.UI.createButton({
title:'Require JS'
});

but.addEventListener('click', function(){
remoteInclude();
});

win1.add(but);
Url : https://dl.dropboxusercontent.com/u/72777663/sayHello.js contains below code :
exports.sayHello = function(name) {
    Ti.API.info('Hello '+name+'!');
alert('Hello '+name);
};

exports.version = 1.4;
exports.author = 'Don Thorp';

Comments

  1. Ivan Skugor 2013-10-07

    I don't think this would be approvable by Apple. Similar approach is used by TiShadow and TiShadow app was not approved by Apple as far as I know. Cheers.
  2. Ingo Muschenetz 2013-10-07

    Based on feedback, we believe this model creates security complications and would not be approved by the Apple app store. Even though this ticket is for Android, we don't wish to encourage behavior that may only work on one platform. If there is a reason why a user may wish to invoke core outside the resources directory (but that code is not remotely downloaded), we could revisit this ticket in the future.
  3. Ivan Skugor 2013-10-07

    As a workaround, downloaded JS code can be evaluated by using "eval".
  4. Ivan Skugor 2013-10-07

    (I think :) Not really sure would Apple approve that)
  5. Lee Morris 2017-03-22

    Closing ticket as "Won't Fix".

JSON Source