Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Fetching template fails on Android 4.0/4.1 when using Appcache manifest. #1356

Closed
joergschiller opened this issue Sep 12, 2012 · 7 comments
Closed

Comments

@joergschiller
Copy link

I encountered an error while developing a mobile web app with AngularJS using an appcache manifest (http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html).

AngularJS can't fetch a template that is cached offline in Android stock browser on Ice Cream Sandwich and Jelly Bean (Gingbread works). The status code returned from XHR is zero comparable to the behaviour of XHR using the file protocol.

The following change works for me and fixes the issue:
joergschiller@63b5e34

What can I provide you to fix this issue?

Greetings
Jörg

@Trott
Copy link

Trott commented Jun 13, 2013

No comment on the fix, but I certainly ran into this bug today. If I have my partials appcached, navigate to a page that doesn't use Angular, then hit the back button, the partials do not get loaded. This was on Android 4.1. My solution was to not appcache the partials, which is unfortunate.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@eugeneos
Copy link

I ran into this issue with Angular 1.1.5. Also, I looked at the master branch of angular/angular.js, and the code there is:

status = (protocol == 'file' && status === 0) ? (response ? 200 : 404) : status;

which is different from 1.1.5 code, but it looks like it still doesn't fix the issue - it should probably be:

status = (protocol == 'file' || status === 0) ? (response ? 200 : 404) : status;

in order to address the appcache manifest scenario. (I've confirmed that this latter line fixes the issue, at least on Android 4.3 emulator). So I really think this issue should be reopened.

@caitp
Copy link
Contributor

caitp commented Dec 10, 2013

Mmm, that change was only made a few weeks ago, and from what I've heard it seems to work --- can you prove that it doesn't?

@eugeneos
Copy link

When you say "it seems to work", has it specifically been tested with an app manifest on Android?
Here are my repro steps:

  1. Create an Angular app with <html manifest="app.appcache">
  2. Configure web server to serve the app.appcache manifest correctly (i.e. with Content-Type of "text/cache-manifest")
  3. Make the app use Angular HTML templates (in my case the app uses Angular directives that load templates from templates/*.html under my app folder)
  4. Configure the app.appcache manifest to point to all relevant files correctly (including the HTML templates!) - see e.g. https://developers.facebook.com/blog/post/2012/07/16/mastering-the-application-cache-manifest-for-offline-web-apps-and-performance/ for format
  5. Start the Android 4.3 emulator. (I'm primarily using the Android SDK emulator but have also seen the issue in the Genymotion emulator; I am guessing this will repro on a real device as well, but I unfortunately have no way of testing this right now; I think this may also repro on older iOS, but I'm not 100% sure about this).
  6. Open the app in the built-in Android browser.
  7. After the app fully loads, close its tab (click the "tabs" icon on top right of status bar, then click "X" next to the app's tab). If this was the only tab open, the browser may close at this point, if so - reopen it.
  8. Open the app again (do not clear the cache before doing this!). HTML templates will fail to load. If you open the debug console (by going to "about:debug" and clicking "Javascript console"), you will see messages such as: "Error: Failed to load template: templates/jqmButton.html"

I am using Angular 1.1.5. I can confirm that if I change the line to the current line in the master branch, "(protocol == 'file' && status === 0)", the bug still occurs, and if I change it to "(protocol == 'file' || status === 0)" the bug disappears.

rafallo added a commit to rafallo/angular.js that referenced this issue Dec 27, 2013
@rafallo
Copy link
Contributor

rafallo commented Dec 27, 2013

I had the same issue like @eugeneos in Angular 1.2.6. Changing from "&&" to "||" helped me.
I think that issue should be reopened to figure out working patch.

Android stock browser on Android 4.1 sets protocol to "http" and status to "0"

tbosch pushed a commit that referenced this issue Jan 9, 2014
Android 4.1 stock browser also returns status code 0 when
a template is loaded via `http` and the application is cached using
appcache.

Fixes #1356.
Closes #5547.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Android 4.1 stock browser also returns status code 0 when
a template is loaded via `http` and the application is cached using
appcache.

Fixes angular#1356.
Closes angular#5547.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Android 4.1 stock browser also returns status code 0 when
a template is loaded via `http` and the application is cached using
appcache.

Fixes angular#1356.
Closes angular#5547.
@geirgp
Copy link

geirgp commented Feb 4, 2014

Altering status 0 to 404 (commit 28fc80b) may seem like the right thing to do in some scenarios but it is not a good solution overall as 404 is a HTTP response code and indicates that the server did actually respond. Status 0 should, according to w3.org definition, be considered "some type of network error or fetch termination" (http://www.w3.org/TR/XMLHttpRequest/#the-status-attribute) - i.e server did NOT respond, very different to the meaning of status 404 - "Not found"

I discovered this code change after upgrading to latest version of angularjs - my code which handles network/connection problems based on status code 0 stopped working since status 0 is now mapped to 404.

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

No branches or pull requests

7 participants