13

What I am trying to do: A dynamic countdown clock in the body of an email

What is causing me pain: Google's decision to cache images for users of the gmail client

I implemented an email countdown clock for my company last November using this technique:

Countdown Timer Image GIF in Email

Worked like a charm, however in December, a major monkey wrench was thrown by Google when they decided to cache all images for people using Gmail clients.

http://kickdynamic.com/update-on-the-gmail-image-change/

So the problem affects all people on gmail clients that open an email a second time. They will see a cached image. For something like a countdown clock, this would cause a lot of harm.

Admittedly this is somewhat of a blind distress call, but has anyone figured out how to do a email countdown clock that is unaffected by google's image caching?

Community
  • 1
  • 1
dt-dev-person
  • 137
  • 1
  • 6
  • don't send over a picture of `hh:mm:ss`. Send over the individual digits 0-9, then use JS to build a clock picture from those component pictures. – Marc B Feb 15 '14 at 19:56
  • 11
    I think most mail clients and webmail servers will not execute Javascript in the message. – Barmar Feb 15 '14 at 20:04

1 Answers1

19

I had the same problem. So with the following headers, I disabled image caching and it works in Gmail too (therefore Gmail Image Proxy respects the cache headers):

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");

Credits to this library note.

Jordan Enev
  • 16,904
  • 3
  • 42
  • 67
  • 1
    @Rohitesh when I did it - it worked. Now I don't have up-to-date information. You can test it as serving an image with the above headers and include it in a mail. If you test it - it will be helpful to share the results here. Thanks. – Jordan Enev Dec 14 '18 at 10:14
  • 2
    Hey @Jordan, it still works. :) Followed your steps for the header, and Google is honoring the no-cache. However, "sending" via GMail, caches the image. So, I have to use an API to end the mails. But on "receiving" the mails, GMail is not caching the images. – Rohitesh Dec 17 '18 at 03:39
  • 1
    I added the exact same headers, and the gmail dose not cache - but, getting multiple image request for the image server when opened the email. ( 2 - 3 request to load a single png/gif ). Anyone know what is the trick to avoid multiple request? – vikas kv Jul 17 '19 at 09:21
  • 3
    My guess is that Gmail does anti-spam validations or other related processes, these trigger email opening more than 1-time and this results in requesting the images multiple times respectively. – Jordan Enev Jul 17 '19 at 09:27
  • 1
    @JordanEnev This happens when I open the email for the first time only, and if I have the Cache Control headers like no-cache, no-store. Other wise it is fine. without these headers even first open will make only 1 req to source. – vikas kv Jul 24 '19 at 13:18
  • I tried to setup these headers via NodeJS using the nodemailer library, but this does not work in gmail. It still rewrites the image uri. We do not have a publically facing cdn for our images, so the image rewrites fails since the google caching system does not have access to our private cdn – thxmike Oct 16 '19 at 21:20