Cache http responses with no-cache header in Electron - caching

I'm trying to wrap an existing web app in an Electron app in order to improve the performance.
I would like to override the cache strategy for certain web service calls as I know it will improve performance based on the way I use the website.
I don't control the web app so I cannot make any changes to that.
I have wrapped the web app in a BrowserView.
Some of the endpoints that the web app using have have this response header: cache-control: no-cache, no-store, no-transform.
I would like to cache the result for 1 minute even though the server tell me not to.
So far I have tried to override the response header like this:
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
let headers = details.responseHeaders
headers["Cache-Control"] = ["max-age=60"]
return callback({responseHeaders: headers})
})
But Electron is ignoring the updated response header entirely.
Any ideas to how I can force another caching strategy than the server suggests?

Related

Disable caching of Web API responses

I want to disable browser caching of all the Web API responses across all the clients. Even though I can use libraries like CacheOutput or CacheCow as suggested in Scott Hanselman's blog but my requirement is not that complex. I just want to disable caching of all the Web API responses and do not need any custom control over it.
How do I do that in ASP.NET Web API 2?
Which headers do I need to set? 'Cache-Control' : 'no-cache'?
Is ETag, Last-Modified, etc needed? Or maybe any other response headers??
It need to be implemented in a DelegatingHandler, right?
Just use the Cache-Control: no-cache header.
Implement it as delegating-Handler and make sure your header is applied (with MS Owin Implementation hook up on OnSendingHeaders(). I'm using it here OnSendingHeaders() Example).

HTTP Vary: Cookie vs Cache-Control: private

I am writing a web application framework. To properly support reverse proxy servers, I want to make sure that whenever the web application is accessing cookie data, pages that are sent to the user are cached only for that user. As far as I know, there are two ways of achieving this:
header('Vary: Cookie');
or
header('Cache-Control: private');
The immediate benefit of using Vary: Cookie is that a reverse proxy server will cache non-authenticated requests. However, we're using Google Analytics which create cookies through javascript - so I am afraid the Vary: Cookie method is unusable?
For your case (using Google Analytics), this will not work as GA sets first-party cookies for ".yourdomain.tld"
As of now, I'm seeing the following first party cookies set by Google Analytics:
_gat_gtag_UA_#####_#
_ga
_gid
Cookies set by a script served by a given domain will only be sent to that domain.
The proxy will not receive the cookies set by google analytics.

HttpWebResponse not providing correct value for headers

I was writing some test scripts to validate the headers for my .net webapi services. When I look at the traffic through fiddler and invoke the service through my browser I see the correct header Cache-Control: no-cache, no-store. However when the service is invoked with a WebRequest from my .NET test class and I read the response, Cache-Control is set to private. Why would I be seeing different response header values based on the client that is calling the service?
As you probably know ASP.NET modifies the rendered HTML based on user-agent, so that's probably what's happening here. http://msdn.microsoft.com/en-us/magazine/cc300549.aspx
So try using the IE9 user-agent string in your webrequest

ie 10 cross domain ajax request

I have developed a web application that makes ajax requests to a web service on a server in a different domain from the server that hosts the web app.
I have configured the web service to do a pre-flight check to set the necessary headers to allow a cross domain request.
In the web app I am using a JQuery client to access the web service. I have set the properties on the Jquery command to allow cross domain access.
$.support.cors = true;
In Chrome this all works fine. In IE9, however the cross domain behavior is only partially successful. All get requests work. But post requests with a content-type of application/json fail because IE9 refuses to make post requests with any content-type except text/html. IE9 switches the content-type on the request and the request fails on the server with a 400 bad request.
I had read that with IE10 the cross domain request would work as in Chrome. But after just testing this, I find that IE10 has the same behavior as IE9. The browser will not set the content-type to application/json. So post requests fail.
Does anyone know whether it is possible in IE10 to do cross domain post requests with other content-types than text/html. This makes writing web apps that do anything more than display data extremely difficult.
Are there other settings I need to make on the Jquery request? Or in the service pre-flight?
What does your $.ajax() call look like? You could try adding data: 'json' to your JQuery call in order to force the data type to be json. You also shouldn't need to set $.support.cors = true;, JQuery should figure this out for you (but its ok to leave it in for now).
I do have the content type param set data: 'json'.
Chrome honors this but IE switches to text/html. I had read that this was a know issue in IE9 and below but that IE10 would be using the same ajax implementation as Chrome, but this is apparently not the case.

How long will Safari cache results from AJAX POST requests in iOS 6.0/6.0.1?

I have recently come face-to-face with the issue of Safari caching the results of AJAX POST requests in iOS 6.0 and 6.0.1, as outlined in this question.
I have implemented a workaround so that the app will now add a Cache-Control: no-cache header to all responses of POST requests. The application, an ASP.NET web app, was previously returning a value of private for the Cache-Control header, which I suppose is the default (we were not explicitly setting it anywhere). No timespan was included.
While the workaround is serving us well for end users that are submitting a request to a particular URL for the first time, users that already have cached data could still be impacted. In the case where no specific timespan for caching is given to Safari, how long will it cache POST request data before it expires?
If you are concerned about this and you want to clear the cached requests, you can always change the POST request by adding some new hidden field with some value you don't even care about. Since this is a new request, the browser should not rely on it's cached response.

Resources