Disabling caching for Angular AJAX requests in Internet Explorer - a step-by-step guide

My Angular application successfully makes HTTP GET requests to the server when accessed on Chrome and Firefox. However, I recently encountered an issue with Internet Explorer where it caches the GET response. This causes a problem when I need to retrieve updated information after making a POST request. Specifically, in IE, the cached GET response is retrieved instead of the new data. I am looking for a way to disable caching specifically for IE without impacting other browsers.

'If-None-Match': '*'

I attempted to use the above code snippet as a request header for my GET calls, but found that it disabled caching universally rather than just for IE. Can anyone suggest a solution to conditionally disable caching for IE only? Alternatively, are there alternative methods to achieve this desired outcome?

Answer №1

CSS

<link rel="stylesheet" type="text/css" href="styles.css">

Python

if 'cache' in response.headers:
    del response.headers['cache']
response.headers['pragma'] = 'no-cache'
response.headers['expires'] = 'Sat, 01 Dec 2001 00:00:00 GMT'

Answer №2

After analyzing the information provided, I successfully implemented this solution for a specific request within a controller without altering the global defaults:

var customConfig = {
    headers: {
        common: {
            "Cache-Control": "no-cache",
            "If-Modified-Since": "0",
            "Pragma": "no-cache"
        }
    }
};

$http.get("path/to/file.json", customConfig)
    .then(function (response){
        //perform actions
    });

Answer №3

When using $http in Internet Explorer, you may encounter issues where the response code is not 200 or 304, causing it to rely on local cache instead.

To address this problem, consider adding headers to the $httpProvider as shown below:

angular.module(ApplicationConfiguration.applicationModuleName)
.config(['$httpProvider', function($httpProvider) {
    //initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};    
    }    

    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';

    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);

Answer №4

Although this thread is old, I recently conducted a test and found that none of the discussed headers are recognized by IE11.

Since IE only considers the URL to determine caching, I decided to add a date to the query string like so:

$http.get("https://myURLWithoutParameters"?t=" + new Date().getTime())
.then(function (response) {
  // Manage response
}, function (response) {
  // Error handling
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS UI router regular expressions allows for dynamic and flexible routing

I'm attempting to find a parameter with two possible values: 'current' or a number with at least 10 digits. Here's what I've tried: url: '/history/{code:^current$|^[0-9]{10,}$}' Although this regular expression suc ...

Using the IE method getelementbyid to target an object within the document

Is there a way to use getElementById to access an object that already exists in the document? I am specifically trying to target the element "test" which is nested within parentDiv1. While this code works in Firefox, it's not functioning properly ...

Creating a loop with resolves to navigate through states in AngularJS with ui-router requires the use of a closure

Within our AngularJS app, I am dynamically creating states using ui-router. Consider an array of states like the following: const dynamicStates = [ {name: 'alpha', template: '123'}, {name: 'bravo', template: '23 ...

Unable to find a solution for creating a new element within the angular UI modal

After struggling to incorporate an Angular UI modal and set default values prior to opening the create person screen, I generated a new person object as follows: var person = {}; person.name = 'default'; Within this function modalCtrl. ...

Angular form submission with action appending key-value pairs

My main objective was to create a form submission using the 'get' method, where key-value pairs are appended to the URI. I referred to http://www.w3schools.com/tags/att_form_method.asp, which explained how setting the form method as "get" should ...

Updates to $scope are not reflecting in the application

My input includes a datalist that is populated by an angular get request as the page loads. <input list="data" /> <datalist id="data"> <option ng-repeat="item in items" value="{{item.data}}"> </datalist> The $http call is straig ...

Using the built-in http module in node.js to upload images via multipart/form-data

I have encountered an issue where I need to send two images and an API key as part of a multipart/form-data HTTP request to an API. The images are retrieved from an AWS S3 bucket, which works fine. However, when attempting to send the image data as part ...

What are the steps to effectively create a cascade of Q promises?

Consider the following scenario as an illustration: I have 3 URLs stored in an array called "urls" The "require" function returns a promise that performs an $http call The code provided is functional, but it doesn't meet my desired outcome since th ...

Retrieving Data from Outside Source using AngularJS

Is there a way to retrieve JSON-Text-Stream data from a specific URL (e.g. SOMEURL/ean.php?id=4001513007704)? The returned result typically appears as follows: { "product": { "ean_id": "4001513007704", "title": "Gerolsteiner Mineralw ...

Exploring the capabilities of UIGrid in conjunction with TypeScript DefinitelyTyped has been a

I've noticed that the latest release of UI Grid (RC3) has undergone significant architectural changes compared to nggrid. I am encountering some problems with the definitelytyped files for nggrid because they are from a different version. Will there ...

Learn the process of extracting a particular value from JSON data and displaying it in HTML by utilizing AngularJS's ng-repeat directive

As a newcomer to angularjs, I am encountering difficulties retrieving and displaying a specific value from a json file in order to showcase it on my view page using angularjs ng-repeat for image source. My goal is to repeat the json file based on a particu ...

Methods to Retrieve Data in Directive

Below is the directive I am working with: directive('checkKey', function() { return { restrict: 'A', scope: { min: '=' }, link: function(scope, elem, att ...

Internet Explorer 11's default document view mode now automatically switches to Edge viewing

I currently have Windows 7 and IE 11 installed on my local machine as I work on an ASP.NET, C# web application that utilizes Bootstrap, jQuery, and more. Recently, I implemented a checkbox dropdown list using the code from this link: . However, when view ...

Dealing with Error 462 in Excel VBA When Using Internet Explorer

This function is designed to loop through the hrefs obtained from the GetData() function, navigate each page, retrieve specific data, and then move on to the next one. Sub CreateDatabase() Dim ieNewPage As InternetExplorer, TableRows As Object, TableR ...

Navigating with ASP.NET 5 Routing and AngularJS Routing

Currently, I am working on an ASP.NET 5 application which also utilizes AngularJS for the front-end. The basic client-side HTML routing support offered by Angular has been successfully implemented in my project. In the Startup class, the default routing is ...

Steps for transferring data from a POST response to the client in NodeJS/ExpressJS

I am currently in the process of setting up an EasyPost API and I need to save some data that is included in a response from a POST route. My goal is to send this data directly to the client for storage, but I am struggling to determine where or how to do ...

struggling to retain data within scope when utilizing localstorage in angular

Currently, I am utilizing the fileReader to read a file, save the image in localStorage, and then display it on the view. In the controller: angular.module('App')controller('publsherProfileEditCtrl', ['$rootScope', '$sc ...

Oops! Looks like the file or directory 'E:clientindex.html' cannot be found

Currently, I am attempting to send an HTTP method from an Angular service to trigger an API on Node.js. However, I keep encountering the following error: Error: ENOENT: no such file or directory, stat 'E:\client\index.html' This is th ...

ngOptions accepts objects as values rather than just option values

I'm currently utilizing a 'getPickupSchedules' directive to populate schedules based on the inputted zip code provided by the user. Upon entering a 5 digit zip code, an $http.get request is made to fetch the schedules corresponding to that z ...

AngularJS: intercepting custom 404 errors - handling responses containing URLs

Within my application, I have implemented an interceptor to handle any HTTP response errors. Here is a snippet of how it looks: var response = function(response) { if(response.config.url.indexOf('?page=') > -1) { skipException = true; ...