angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

IE11 not getting new promise data

Open Martinspire opened this issue 12 years ago • 8 comments

Perhaps i found an IE Bug? I'm using a repeated promise (via $timeout to a resource) with some data i need to get. Its an external api (which can change stuff too so i need it somewhat fresh) and when i change values in IE it switches me back to the original value, even though in Chrome i see the new value appear. When i open IE Devtools it shows me the correct values and works as expected.

Situation: Data from API>Data from service->Data from Controller which is repeated by making a $timeout loop it->Data in view Change data in view reverses the path and its being submitted (i can see new values in Chrome) but doesn't reflect on IE11. When i hit refresh or open Devtools it shows me the new value though. When i alert the value, it shows the old one (unless i open devtools)

I've already tried disabling resource cache (globally and locally) and that doesn't help. I've also checked to see if the timeout is running properly (if i can set new values via timeout in controller) and that also works. It just doesn't get the new values.

No issues in Safari, Chrome, Firefox. Only IE11 (or perhaps lower too) have these issues. And only when devtools isn't open.

I've checked to see if its related to console.log or something but that doesn't seem the case (i've got a version running minified and without console) and that also works normally. But IE11 shouldn't have a problem anyways.

I'll see if i can work up a jsfiddle or example but i need to do some work on that as it requires me to pick some code from my project. Alternative would be that i make a small video to explain it. But before i do that, perhaps others have had this issue?

Martinspire avatar Aug 11 '14 09:08 Martinspire

I fixed it by using the following code:

var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
    $httpProvider.defaults.cache = false;
    if (!$httpProvider.defaults.headers.get) {
      $httpProvider.defaults.headers.get = {};
    }
    // disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
    //.....here proceed with your routes
}]);

It seems that IE isn't handling the proper headers so it doesn't refresh. I noticed this when checking the backend if i got requests but it didn't (even if the alert from inside the $resource told me so).

I also needed this on the server (express):

res.header('Access-Control-Max-Age', 0);
res.header('Cache-Control', 'max-age=0,no-cache,no-store,post-check=0,pre-check=0,must-revalidate');
res.header('Expires', '-1');

This way i really know it is fresh data. Downside is still that it is polling pretty frequent and making my app slower but we'll be implementing long-polling or even webworkers soon. Still, somebody might need this sometime.

And if somebody with better knowledge about headers, $resource, IE11 could take a look, go ahead!

I'm not closing this yet as i'm not entirely sure this is IE's fault

Martinspire avatar Aug 11 '14 12:08 Martinspire

+1. We have the same problem in our project. The views don't refresh anymore after deleting/editing an object in IE. In Chrome/Firefox/Safari it works. Hope this is fixed soon!

pdeveltere avatar Sep 15 '15 13:09 pdeveltere

+1. Yeah thanks it solved the problem but it faced another, I can't load the font awesome on IE8-IE11 but working normally in EDGE :(

gilangaramadan avatar Nov 04 '15 09:11 gilangaramadan

@gilangaramadan suspect you've already solved this, but webfonts won't load in IE8-11 with a Cache-Control: no-cache header -- you'll need to exempt your font file extensions from that. (And while you're at it, exempt other statics too, like images.)

ianlyons avatar May 25 '16 16:05 ianlyons

This looks like an IE bug / a server config issue.

Narretz avatar Jul 18 '16 20:07 Narretz

+1, this was a great fix! I had the exact same issue, and couldn't figure it out for the better half of a day.

jrthompson33 avatar Jun 16 '17 21:06 jrthompson33

Thanks! I had the same issue, now its gone :)

dfernandez-dev avatar Jun 28 '17 02:06 dfernandez-dev

Where do I have to put the codes @Martinspire provided ? in the JSP (HTML) page ?

Thanks in advance

Gallyket1 avatar Jul 30 '18 12:07 Gallyket1