avoid browser image caching in webmail gmail - email

Is there a way I can prevent browser image caching in an HTML email without using Javascript? I have an HTML email with an image that I want to be reloaded every time the email is opened in Gmail webmail. Right now it seems the browser is caching the image.

Unfortunately, since 2013 Gmail started adding images to its native web interface and mobile apps cache, but external apps and services retrieving mail from Gmail will download the normal images.
This snippet placed in the embedded CSS area can fix this issue by disabling the cache:
header('Content-Type: image/jpeg');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

Related

Cache-Control header to bust device cache but allow CDN

I am implementing an HTTP polling mechanism to detect device network status. I am planning to make a periodic GET request to a static file /static/byte.txt to validate the device's internet access.
I am using the Cache-Control: no-cache request header to make sure I am not served with a cached copy of the file on the device (which defeats the purpose). But I would like to still use any cached copy of the file on the CDN, as there is no need to download the file from the origin (my servers) every time. Does anyone know of a way to set the cache control headers to achieve that? Thanks!
The Cache-Control request header is a poor fit for this use case as both the client HTTP library and the CDN will assign the same meaning to whatever cache control directive you choose.
Instead, I recommend using a Cache-Control response header. In the response, you can use something like Cache-Control: max-age=0, s-maxage=604800, which indicates that the client should not cache the response but the CDN can cache it for up to a week (604,800 seconds).

Facebook Messenger Bots: Image Caching

I am building a bot for FB Messenger. One of the scenarios require using the Generic Template of the sendAPI. However, it seems like FB Messenger is caching the images included in the template. Is there a way to avoid that?
One thing to note here is that I am using ExpressJS and I am serving the images through a normal controller using res.sendFile(..) as opposed to serving them as static files. I also disabled caching using the following:
app.use(function(req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next()
});

How do I convert a REST HttpRequest captured via a web proxy tool into a link a user can click?

I have used a proxy tool to capture a certain REST HttpRequest. The request is a HTTP PUT command followed by an extremely long REST link containing specific data that gets sent to the server.
In the proxy tool it looks something like this:
Header
PUT http://XXX.XXX.XXX.XXX:8080/rest/blah/blah/.../ HTTP/1.1
Host: XXX.XXX.XXX.XXX:8080
User-Agent: Mozilla/5.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-language: en-us, en:q=0.5
Proxy Connection:keep-alive
Content-Type:XMLHttpRequest
Referer: http://XXX.XXX.XXX.XXX:8080/plugins/blah/blah
Content-length: 11156
Cookie: JSESSIONID=<really long alpha numeric>
Body:
{"links":{"self":"/rest/plugins/1.0/blah/blah.....
...
... lots and lots of JSON text
}
}
So the proxy tool has been helpful in identifying what the request looks like.
But the only way to generate this request is by clicking a button on the webpage. I would like to send exact same request on my own (like creating a custom link that when clicked generates a similar request to the one shown above). How do I do this?
Also, anything I type in the web browser URL area automatically is a "GET". How do I force a PUT?
Cookie: JSESSIONID=
This clearly indicates that the API you want to use is not a REST API, because it violates the stateless constraint of REST.
How do I force a PUT?
Probably you don't have a way to do that. It depends on the security settings of the web API. If you want to do this with AJAX from the browser, and your domain is different from the APIs domain, then you need a CORS header from the API, which allows your domain to read cross origin responses. By PUT the browsers sends a preflight first, and if it cannot read the response, it will never send the real PUT. Security policy and other headers can block XSS in the browser, so you probably don't have a way to do this from browser.
You can do this from your server by copying the request details and catching the session id somehow.
If the API allows access to 3rd party clients, then I suggest you to contact with them. If not, then you 99% that you won't be able to do this.

Asp.net web api not setting content length header

I am building a RESTful services using web api. My client is a HTML5/Jquery application. The service and application works perfectly on IIS 5.1. But when i switch to IIS 7.5, i see the response contains a Transfer-Encoding: chunked header and my client doesn't understand/render UI elements(btw this HTML 5/JQuery stuff is done by a third party and i don't want to change their code. why should i ? after all, it was working fine till we moved to IIS 7.5). My questions are :
How/Where do i add a "Conetent-Length" http header in web api so that IIS doesn't "chunk" encode the response?
Is there a way to disable this encoding at the site/server level in IIS 7.5 ?
When i access the service from browser/fiddler i get the proper response(xml/json). I am using Json.net formatter.
Use
myHttpResponseMessage.Headers.TransferEncodingChunked = false;
to turn off chunked encoding.
This could be due to this bug which is fixed post-beta:
"DevDiv 388456 -- WebHost should not use Transfer-Encoding chunked when content length is known"
http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/06f52b894414#src%2fSystem.Web.Http.WebHost%2fHttpControllerHandler.cs
Setting response.Headers.TransferEncodingChunked = false; didn't work around this issue for me.
Also you are likely to apparently be getting different results in Fiddler due to having "Decode" button pressed at the top which automatically de-chunks the response and removes the transfer-encoding header from the response.

How to programmatically disable browser caching

I have question regarding disabling browser caching. I have already found few solutions, and just want to know if there are better or more common approaches. So I have GWT applications and in order to disable cashing I may use next options:
Adding to URL dummy parameter
Putting on the HTML page <meta http-equiv="pragma" content="no-cache">
Setting HTTP headers:
header("Pragma-directive: no-cache");
header("Cache-directive: no-cache");
header("Cache-control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");
The most important are the
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); #Expires sometime in the past
header("Cache-control: no-cache"); #Disables caching
In addition, add the unique parameter to the url to be sure. If you are using browser back-button sometimes the entire DOM is cached and no new content is fetched unless you do it dynamically using javascript and adding a unique id to your request.
Normally, you want to set most of these headers in your server configuration so that you can serve normal images and other static content with the right headers also.