Giter VIP home page Giter VIP logo

Comments (14)

micky2be avatar micky2be commented on May 16, 2024

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.

zhougn avatar zhougn commented on May 16, 2024

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.

micky2be avatar micky2be commented on May 16, 2024

From what I recall, everything in the bundle is copied to the cache.
So in theory it should work

from cordova-app-loader.

zhougn avatar zhougn commented on May 16, 2024

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.

micky2be avatar micky2be commented on May 16, 2024

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.

zhougn avatar zhougn commented on May 16, 2024

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.

ObjectiveTruth avatar ObjectiveTruth commented on May 16, 2024

@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.

betorobson avatar betorobson commented on May 16, 2024

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.

zhougn avatar zhougn commented on May 16, 2024

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.

ObjectiveTruth avatar ObjectiveTruth commented on May 16, 2024

@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.

betorobson avatar betorobson commented on May 16, 2024

That looks pretty cool. I will try it. Thank you.

from cordova-app-loader.

minhtc avatar minhtc commented on May 16, 2024

@ObjectiveTruth I was having the same issue with you. Could you share your solution here?

from cordova-app-loader.

guv3n avatar guv3n commented on May 16, 2024

@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.

markmarijnissen avatar markmarijnissen commented on May 16, 2024

Use cache.loader.get or manifest.root + originalPath to find the correct reference to the image source

from cordova-app-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.