Comments (14)
Sorry I'm a bit late to post an answer but your src is wrong here. It will try to look for the image where the html file is. Which is not in the cache.
You have to put cdvfile://localhost/persistent/app/resources/img/image.png
directly there instead.
from cordova-app-loader.
I have a related problem:
I understand that when my App gets updated, I have to put cdvfile://localhost/persistent/app/resources/img/image.png
directly in my html, because the image is downloaded in the cache.
But what if when my App first time runs and there is nothing to update? In this case, all my html and images are still in the bundle folder, not in the cache, there is no such file cdvfile://localhost/persistent/app/resources/img/image.png
. Instead resources/img/image.png
is the correct path.
While I don't want to keep two different versions of my html files, is there any solution for the problem?
What I can come up with is to copy all the bundle files to the cache folder when my App first time run, same as @betorobson's thought here: #50
Is it good idea? And how can I do that?
from cordova-app-loader.
From what I recall, everything in the bundle is copied to the cache.
So in theory it should work
from cordova-app-loader.
Just tested on iOS, it doesn't seem to work, and I don't see any related code.
I'm using the latest version of cordova-app-loader.
from cordova-app-loader.
The code is in there
https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaAppLoader.js#L211-L217
https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaAppLoader.js#L274
from cordova-app-loader.
I think I understand why my App doesn't work in that way, thanks so much.
When there is no file to be deleted or to be downloaded, AppLoader#check method will resolve(false)
according the code:
https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaAppLoader.js#L236-L246
And I copied a piece of code from
https://github.com/markmarijnissen/cordova-app-loader/blob/master/autoupdate.js#L35-L45
function check(){
loader.check()
.then(function(){
return loader.download();
})
.then(function(){
return loader.update();
},function(err){
console.error('Auto-update error:',err);
});
}
The loader.download() is never called, that's why the bundle files are not copied.
from cordova-app-loader.
@zhougn, I was having the same issue. I resolved it by programmatically adding cdv://
to each resource I referenced based on whether it was downloaded or not. Its pretty ugly.
Did you find a cleaner solution? I figure having it ALWAYS copy the files to the cache would be best and just append all resources with cdv://
from cordova-app-loader.
It seems to be a long assert, but for me, It looks like that needs just a slight change, before check if has any file changed listed on manifest it could copy all those listed files from bundles to cdvfile:// and them all references to those files can use cdvfile://.
This change could be follow by a kind of parameter or something like that, a optional setting. I don't know actually, it is just a tip but I can be wrong.
For now, how I said in other post, I'm using a timestamp file which is bump "updated" after build my project in order to force all my file to be copied to cdvfile://
from cordova-app-loader.
I end up with changing bootstrap.js
a little to make sure all bundle files are copied to cache folder on first time run, even when there is no network for the app to check update from remote server. So all the resource references can be prepended with cdv://
.
It works for me, but still ugly, and this requires cordoba-app-loader-complete.js
to be loaded before bootstrap.js
. It would be great if some simple settings can make things happen.
@@ -1,4 +1,38 @@
(function(){
+
+function copyBundleFiles(manifest) {
+ var isCordova = typeof cordova !== 'undefined';
+
+ var fs = new CordovaPromiseFS({
+ persistent: isCordova, // Chrome should use temporary storage.
+ Promise: Promise
+ });
+
+ var loader = new CordovaAppLoader({
+ fs: fs,
+ localRoot: 'app',
+ serverRoot: './',
+ manifestUrl: 'manifest.json',
+ mode: 'mirror',
+ cacheBuster: true
+ });
+
+ loader.manifest = manifest;
+
+ function downloadBundle() {
+ manifest.root = 'cdvfile://localhost/persistent/app/';
+ loader.newManifest = manifest;
+ return loader.download().then(function() {
+ loader.update();
+ location.reload();
+ });
+ }
+
+ fs.deviceready.then(function(){
+ loader.check(manifest).then(downloadBundle, downloadBundle);
+ });
+}
+
// Retrieved and slightly modified from: https://github.com/typicode/pegasus
// --------------------------------------------------------------------------
//
@@ -68,6 +102,7 @@
if(!manifest){
var url = (s? s.getAttribute('manifest'): null) || 'manifest.json';
// get manifest.json, then loadManifest.
- pegasus(url).then(loadManifest,function(xhr){
+ pegasus(url).then(copyBundleFiles,function(xhr){
console.error('Could not download '+url+': '+xhr.status);
from cordova-app-loader.
@zhougn , oof that works but I'm worried about the hard coding cordova-app-loader-complete.js
into the device, incase there's any updates in the future. At least, that's the concern with my use case.
Its an option at least.
Let me know if you have any ideas for a cleaner solution, hopefully we can build it into the project.
from cordova-app-loader.
That looks pretty cool. I will try it. Thank you.
from cordova-app-loader.
@ObjectiveTruth I was having the same issue with you. Could you share your solution here?
from cordova-app-loader.
@zhougn I tried your piece of code to copy all files to cache to be able to getScripts from cdvfiles://.. but the problem is that after that, the "real" update won't work anymore because files from the update are the same as the one copied in cdvfile (this is made to avoid loop updating if I understand well)
"New manifest available, but an earlier update attempt failed. Will not download."
Did you find a solution to this ?
from cordova-app-loader.
Use cache.loader.get
or manifest.root + originalPath
to find the correct reference to the image source
from cordova-app-loader.
Related Issues (20)
- Auto-reset when updating apk HOT 2
- Is it possible to custom remote file url
- problem and suggest HOT 1
- How to deal with fonts
- Calling download() never finishes. HOT 3
- onSingleDownloadProgress is not a function HOT 3
- Error: Not allowed to load local resource
- Remote Updating HTML files? HOT 2
- file is long time cached by server,the file do not affected!
- Getting FileError
- stuck when starting the app
- Multiple servers: one server per each AppStore app version
- Updates not working in combination with cordova-plugin-crypt-file HOT 1
- Still having issues with Phonegap Developer app
- Question: Does this way of auto-updating go against the guidelines of Apple? HOT 3
- Error code 1 when cloning demo - no exception message
- Cordova plugin HOT 1
- download promise is neither getting resolved nor rejected HOT 1
- app.js file inside www is not updated with latest code HOT 4
- This plugin not working in android
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-app-loader.