Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs application not handling 304 responses when retrieving html templates from firebase hosting server

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: ""
like image 353
adolfosrs Avatar asked Aug 17 '18 16:08

adolfosrs


1 Answers

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

like image 128
Guoshun Wu Avatar answered Sep 30 '22 01:09

Guoshun Wu