Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

html - How to prevent loading image from cache when the src is a redirect url to the actual image file

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...