9

I have some users not being able to access some templates on my angularjs application when my server responds with status code 304. Angularjs is logging [$compile:tpload] as you can see bellow and the views are not being shown to the users. So somehow angular is not getting the views from cache. The issue seems to happen very intermittently and the page starts work properly again after a clean browser cache + page refresh.

I'm running Angularjs v1.6.6 with ui-router v0.3.2 and I'm hosting my static files on firebase hosting. Is it something that was fixed on latest versions? Otherwise, how should I handle this case?

[$compile:tpload] http://errors.angularjs.org/1.6.6/$compile/tpload?p0=%2Fjs%2Ftemplate1%template1.html&p1=304

Possibly unhandled rejection: {"data":"","status":304,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","cache":{},"headers":{"Accept":"text/html"},"url":"/p/p.html"},"statusText":"","xhrStatus":"complete"}


Caught Request/Response using LogRocket

URL: "https://url.com/js/p/a/template.html"
method: "GET"
status: 304
duration: "00:00.061"

REQUEST
headers
  Accept: "application/json, text/plain, */*"
body: null
credentials: ""
mode: ""
referrer: ""


RESPONSE
headers
  cache-control: "max-age=3600"
  date: "Sat, 15 Sep 2018 20:03:12 GMT"
  etag: ""f166a7577a895x3f7dcc5accae97dcba""
  expires: "Sat, 15 Sep 2018 17:45:33 GMT"
  vary: "Accept-Encoding"
  via: "1.1 varnish"
  x-cache: "HIT"
  x-cache-hits: "1"
  x-served-by: "cache-bma1622-BMA"
  x-timer: "S1537041792.121483,VS0,VE1"

body: ""
adolfosrs
  • 9,286
  • 5
  • 39
  • 67
  • Possible duplicate of [Why am I getting "(304) Not Modified" error on some links when using HttpWebRequest?](https://stackoverflow.com/questions/2603595/why-am-i-getting-304-not-modified-error-on-some-links-when-using-httpwebrequ) – Devin Fields Aug 17 '18 at 17:24
  • @DevinFields Sorry, this is completely different. I do understand that 304 is not an error and the client should handle it. The problem I'm reporting is that my client application is not handling it properly. – adolfosrs Aug 17 '18 at 17:27
  • There is discussion in those answers as to how to handle it. This may even be enough for you: Another trick is to add question mark ? at the end of the URL string of the requested page: 'http://localhost:52199/Customers/Create?' – Devin Fields Aug 17 '18 at 17:34
  • 1
    In any case, a working example would help. I can't help much further without it. – Devin Fields Aug 17 '18 at 17:35
  • I don't want to force refetching the templates. I need angular to show the ones that are supposed to be cached. – adolfosrs Aug 17 '18 at 17:37
  • Possible duplicate of [Why is $http.get returning 304 error](https://stackoverflow.com/questions/41942074/why-is-http-get-returning-304-error) – georgeawg Aug 17 '18 at 18:03
  • What you see in Network tab? If you see normal response - problem is with your js, but if you dont - prodlem with something else. – Petr Averyanov Sep 20 '18 at 13:35
  • @PetrAveryanov I see 304 responses. – adolfosrs Sep 22 '18 at 00:51

2 Answers2

1

I recently faced the same issue.

After some digging, I finally found the root cause is the modification date of template HTML files are too old. I found that if your template files modified earlier than 1997-0726 05:00, the issue would happen.

Note that my testing web server islighttpd, other webservers may have a similar issue but the date may vary.

For example, you can execute the following command to reproduce this issue or fix the issue, where the *.html file are angular template files.

  1. Reproduced issue.

date -s "199707260500" && touch login.html; touch status.html

  1. Fix the issue.

date -s "199707260501" && touch login.html; touch status.html

XPD
  • 1,121
  • 1
  • 13
  • 26
Guoshun Wu
  • 11
  • 2
-1

You could try to add this to your app.config function.

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

In other cases of people that saw this "error", they had fix it using that code as workaround.

Samuel Roberto
  • 441
  • 3
  • 7