I am working on a project where I am trying to track email opens by inserting an image in it and detecting when it is loaded from the server. The loading is performed using a php script. I am trying to load 2 different images. Lets call them image1 and image2.

I changed the image that I was loading (from image1 to image2) and then sent the emails again, but the image1 was displayed. This happened for the next 5-6 emails when image2 wasn't displayed. I tried running the script through the browser before I sent any emails and it loaded image2.

I then cleared the cache and resent the emails and then I could see image2.

My question is - Does chrome cache scripts and emails along with images?
Is caching the reason why I couldn't see the images or might there be some other reason?

Thanks

EDIT:
I tried switching back to image1 again. Worked when run in the browser. But in the first attempt in the emails, I still saw the Image2. After clearing the cache, only windows live mail showed image1. Gmail still showed image2.
Any ideas?

EDIT:
After 5-6 more emails, still looking at image2 in gmail. What's going on here?

EDIT:
Finally after deleting the old threads in gmail and closing and opening it again, I can see image1

Hi,

maybe your problem is related to the recently privacy changes made by Gmail.

They are now caching HTML emails and so, the included images are not pulled directly from your server but from their proxy servers. It seems that only the first request can be tracked because they have to get the images from your server, then the images will be cached on their end for an amount of time and if two users receive the same image there will be only one request from your server, not two as expected so, right now, it seems that the subsequent openings cannot be tracked.

But if you create a dynamic tracking image, which differs for each user at each newsletter, then Google has to request it at least the first time, for everyone.

For more information check these links:

commented: Thanks. That does clarify some things but my actual question still remains. Do browsers cache scripts and emails? +0

Please reply by post, not by vote.

Do browsers cache scripts and emails?

If for script you refer to the PHP script generating the email then no, because PHP will output HTML to the client. When you send a mail, you cannot modify the code, you can only change the images remotely, but the Gmail change, makes this more difficult.

A part that, if you browse to Gmail and open the Chrome javascript console, you can check the headers sent to the browser: open a mail, select the Network tab, then reload the page.

You will see the elements received by the browser, click on XHR and apply the filter rid=mail, you will select two elements: one of these two (the text/html type document) is the message container with HTML included.

Clicking on this element you open a window with these tabs:

Headers | Preview | Response | Cookies | Timing

if you click on Headers > Response Headers you will see that the Google server sends something like this:

alternate-protocol:443:quic
cache-control:no-cache, no-store, max-age=0, must-revalidate
content-encoding:gzip
content-length:3621
content-type:text/html; charset=UTF-8
date:Sat, 22 Feb 2014 18:19:31 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:GSE
status:200 OK
version:HTTP/1.1

As you see the directive is to not to cache. So this means, that if the browser acts correctly it will not save the email. You can verify it by typing in the URL bar the command about:cache and then by searching (CTRL+F) for rid=mail, you should not find any match. This happens for privacy and security reasons.

Check the Browser Security HandBook for additional information:

A part this, I cannot help much more without seeing your code.

Thanks. That helps.
I think why that "caching" was taking place was because I was using the same URL to load the images. Since google is cahcing images from URLs I am assuming that when it sees the same URL, it simply assumes that the image is going to be the same and loads it from its servers, that is until the cache expires and it has to reload the images.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.