Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was 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

Description

@joergschiller

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

Activity

  1. Trott commented on Jun 13, 2013

    @Trott

    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.

  2. btford commented on Aug 24, 2013

    @btford
    Contributor

    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!

  3. eugeneos commented on Dec 10, 2013

    @eugeneos

    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.

  4. caitp commented on Dec 10, 2013

    @caitp
    Contributor

    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?

  5. eugeneos commented on Dec 10, 2013

    @eugeneos

    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.

  6. added a commit that references this issue on Dec 27, 2013
    5a04c93
  7. rafallo commented on Dec 27, 2013

    @rafallo
    Contributor

    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"

  8. added a commit that references this issue on Jan 9, 2014
    28fc80b
  9. added 2 commits that reference this issue on Jan 27, 2014
    d71ffcb
    563abd4
  10. geirgp commented on Feb 4, 2014

    @geirgp

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions