Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Question about the iOS app reload: drop cache after update installation #47

Closed
nikDemyankov opened this issue Nov 27, 2015 · 20 comments
Closed
Labels
Milestone

Comments

@nikDemyankov
Copy link
Member

@dongdh wrote in #18:

It's a great plugin,

I just have one question, is it possible to restart app automatically and apply the new code.

Because it seems I need to restart app 2 times before seeing changes (I did changes in some html template)

Or am I using this wrong.

@nikDemyankov
Copy link
Member Author

Are you using local development add-on, or you are testing with the real server?

@dongdh
Copy link

dongdh commented Nov 27, 2015

I am testing with real server, I have tried different configurations

  1. with auto-load set to true or false
  2. manually call fetch and install update
  3. different settings with start, resume and now

@nikDemyankov
Copy link
Member Author

Is it Cordova or Ionic project? And on what platform you are testing: iOS or Android?

@dongdh
Copy link

dongdh commented Nov 27, 2015

I tested on iOS only, I have some own code build between cordova and ionic. the update works after I restart app 2 times, seems its not applied before I manually restart the app.

@nikDemyankov
Copy link
Member Author

That's strange. Will try to reproduce that.

Just of curiosity: if you will try to use local development add-on - problem remains, or everything works? Let him do all the work. You can look into the docs on how to use it.

@dongdh
Copy link

dongdh commented Nov 27, 2015

I set "update": "now" in chip.json, set in config.xml, reload index.html when updateInstalled event is triggered.
document.addEventListener('chcp_updateInstalled', function() {
document.location.href = 'index.html?var='+new Date().getTime();
}, false);
I need to manually close the app, and start it again to get the effect of the new change. maybe this is the way it intends to work.

A question would be is it possible to apply the change directly, or restart the app automatically, (what I did to restart is just reload index.html, maybe its not enough.)

@dongdh
Copy link

dongdh commented Nov 27, 2015

the change I did is just a very minor text change on one of the ionic page template.

@nikDemyankov
Copy link
Member Author

Well, it should reload the page automatically when the update is installed. But for some weird reason, in your case, it doesn't... Will investigate.

@dongdh
Copy link

dongdh commented Nov 27, 2015

I tried both iOS emulator and IOS phone, I run 8.4
Here id my config.xml that has to do with chcp







my chcp.json
{
"name": "xxxx",
"s3bucket": "xxxxx",
"s3region": "eu-west-1",
"ios_identifier": "id123456789",
"android_identifier": "xx.xxx.xxxx",
"update": "now",
"content_url": "xxxxxxxxx",
"release": "2015.11.27-15.25.57"
}

@dongdh
Copy link

dongdh commented Nov 30, 2015

Can someone guide me what is the correct configuration if expect app to reload with new update without manually restart app?

@dongdh
Copy link

dongdh commented Nov 30, 2015

Hello, I am looking through some code and try to understand, can you give me a guide on where the app is reloaded after installation success? do you restart the web view or? I was thinking if there is some cache involved when do a refresh of the url in cordova.

@dongdh
Copy link

dongdh commented Nov 30, 2015

Ok, found where it reloads the page.

@dongdh
Copy link

dongdh commented Nov 30, 2015

Tested some more, it seem the file in Library/Application support is updated, but in the running instance of the app, it still loads the old file.

@dongdh
Copy link

dongdh commented Nov 30, 2015

I read somewhere iOS has trouble clean cache for web view for local html. this doesn't sounds good:(

@dongdh
Copy link

dongdh commented Nov 30, 2015

http://stackoverflow.com/questions/2523435/how-to-clear-uiwebview-cache

don't know if this link helps, but it does seem there are no really good solution to this...

@dongdh
Copy link

dongdh commented Nov 30, 2015

Well, I am temporary solving it by always load js and html with timestamps, but it will be really nice if somehow the web view cache can be totally cleaned.

@tmchng
Copy link

tmchng commented Dec 1, 2015

+1 I also encountered the same problem.

Steps:

  1. Create a mock server serving www using http-server
  2. Deploy the same www content onto an emulator. Now the server and device have the same content
  3. Make an edit in www. Generate new config/manifest without deploying
  4. Try relaunching the app on emulator. I had to do it twice before I saw the change

@dongdh
Copy link

dongdh commented Dec 1, 2015

I think the problem is based on all js, css, img resources is still cached when you reload web view, so a workaround will be always load resources with timestamp. example src="xxxx.js?23948uioew098"

If you are using requirejs, there is a parameter you can set in config that always load files with an extra param,

@nikDemyankov
Copy link
Member Author

Yes, the problem is with iOS and how WebView caches css and js files. I use one dirty hack to solve it, it worked before. But for some reason it's not working for you... As a workaround - yes, you can add some random query parameter to the js and css files, as you showed.

I read http://stackoverflow.com/questions/2523435/how-to-clear-uiwebview-cache before, tried hacks from there, but didn't really helped.

Will continue to search for better solution on that.

@nikDemyankov nikDemyankov changed the title Question about the app reload Question about the iOS app reload: drop cache after update installation Dec 2, 2015
@nikDemyankov nikDemyankov added this to the v1.2 milestone Dec 29, 2015
@nikDemyankov
Copy link
Member Author

In v1.2.0 I have changed the way on how web files are stored. Now each release has it's own www folder. Because of that after the update css files will have a new absolute path, and WebView will use the new version, instead of the cached one. As a result - no need for timestamp hack in the file path.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants