Reputation: 1363
How can I access the resources (CSS, JS and images stored in the project folders) from Worklight? For example is there an absolute path (a Worklight URL) that points to local internal Worklight resources? Or is maybe another way to load resources from filesystem? (The reason I'm trying to load resources from local is to speed up the page loading)
Upvotes: 0
Views: 219
Reputation: 1363
The only way I managed to access local fiiles in Worklight running an Android environment is using a XMLHttpRequest
:
//Works only on Android
function prendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {
var xmlhttp = new XMLHttpRequest();
var risposta = "";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4
&& (xmlhttp.status == 200 || xmlhttp.status == 0)) {
risposta = xmlhttp.responseText;
alert(risposta);
}
}
xmlhttp.open("GET", "file:///android_asset/www/default/"
+ percorsoPiuNomeFile, true);
xmlhttp.send(null);
}
Usage example:
prendiCaricaRisorsaWorklight("css/cssInterno.css");
prendiCaricaRisorsaWorklight("js/jsInterno.js");
This shows on Android an alert with the file content.
Upvotes: 0
Reputation: 44516
Edit: from discussion in the comments it sounds like only looking at the filesystem in the rooted device should suffice.
Edit 2: If what you are looking for is the fastest option to load resources, you shouldn't load them remotely to begin with. Put the index.html in the device. You can't both use Portal to load content remotely, and expect fast loading time. By definition, by loading content remotely, you Will experience possible slowdowns.
Worklight does not supply this path.
Theoretically, you may be able to access the application's sandbox (and thus the web resources) by using the Cordova File API.
You can get a reference to the device's filesystem:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
From there you could access the application's sandbox and find the desired file(s). Since you are the one putting the resources in the app, you should know where you've placed it.
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
To experiment and find out the paths to the content, you can root your device and then via Eclipse you could traverse the file system. This way you should be able to find the path to the file you've placed.
Upvotes: 2