As discussed here, IE is bad about caching things when using ajax (i.e., $route and $http). A brilliant solution to this problem can be found here.
We use many angular apps on our site, so in an effort to ensure the caching issue doesn't occur for other developers working on other angular apps, I would like to add the above proposed solution to every Angular app on our site as a matter of course. If our style guide included the following, a developer would be more likely to include it when building his own app, and would successfully avoid the very dangerous IE issue. After all, not many developers I know actively develop in IE anymore.
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';
// routes go here...
}]);
What this code does is force IE not to cache templates and to issue server requests for $http calls instead of pulling the results from its cache (which can be really bad if your data is dynamic -- which it may very well be).
The problem with adding the code above for every Angular app is that the app may or may not be injecting ngRoute into the app's dependencies. If the ngRoute is not present, an injection error will occur.
So, the question is this: Is it possible to do a check for the presence of an injected dependency in Angular? I would love to be able to do something like the following:
var myapp = angular.module('ordersApp', [
'ngTouch',
'ngRoute',
'ngAnimate',
'myController'
]);
if(myapp.has_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';
// routes go here...
}]);
}