-2

All:

When I try to solve the problem that when load image from cache, I got some answers from this post:How to force a web browser NOT to cache images

It talks about add a timestamp to the src like

<img src="picture.jpg?1222259157.415" alt="">

But in my case, it is not a direct image url, it is avatar url from github like:

<img src="https://avatars.githubusercontent.com/u/614?v=3" alt="">

When I add a timestamp 79399.92599998368 to it, it becomes:

<img src="https://avatars.githubusercontent.com/u/614?v=379399.92599998368" alt="">

I wonder why this src can still be correctly recognized and get the image even the url changed? Could anyone tell me why this works and how browser deal with this?

Thanks

Community
  • 1
  • 1
Kuan
  • 11,149
  • 23
  • 93
  • 201

1 Answers1

3

A question mark (?) in a URL separates location and a query string, listing GET arguments.

In this case, github simply ignores those arguments and serves the image identified by the location part. In other words, github just looks at the first part and thus always serves the same content, but a user's browser obviously cannot predict this, thus needs to always load the content if the whole URL doesn't exactly fit the cached one.

Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89
  • Could you suggest any better way to do this? – Kuan May 14 '15 at 17:35
  • The only other way I see is using HTTP headers on the image server: http://stackoverflow.com/a/728685/1090166 But since the image you're interested in is on github (and not controlled by yourself), this is not possible for you. – Cedric Reichenbach May 15 '15 at 09:47