I found that some website use parameters on image src
like ?v=1390510765392
what is it used for ?
<img src="image.jpg?v=1390510765392" />
Found on that Angularjs example
I found that some website use parameters on image src
like ?v=1390510765392
what is it used for ?
<img src="image.jpg?v=1390510765392" />
Found on that Angularjs example
I can think of two possible uses...
If the parameter randomly changes every time the page is loaded, then it's a common means of preventing the browser from caching the image. This would force the browser to always request a new one (because the URL is different) so that the user always has the latest version.
If image.jpg
isn't actually an image but rather a code-driven server-side resource which responds with an image, then URL parameters would be a way to pass an identifier to that resource to identify which specific image data to download. (Such as if the images, or at least references to them, are stored in a database.)
The first one is very likely what's happening here, though the second is certainly possible.
The src
attribute of the element is simply passing the GET
variable v
to the server at the image.jpg
endpoint with a value of 1390510765392
. Without examining the server-side code, it is unclear why the developer is doing this. A few possibilities come to mind:
image.jpg
could actually be a script (or interpreted by one) despite the .jpg
extension, in which case it is possible that 1390510765392
is a resource token used to retrieve a specific image.src
attribute without actually changing what it points at, thus invalidating any client-side (or intermediary) cache of the image and forcing it to reload, in which case the server itself likely ignores v
.It allows for the name of the image to remain the same but by appending the query string it prevents browsers from using a cached version of the image. The query string essentially makes the URL "new" so the browser goes and gets what it believes to be a new resource.
It's used to avoid image to be served from browser cache (because the URL is different if date changes and it makes no effect on images)
Another possabilty is to avoid flushing CDN resources when the image changes preventing the user from seeing an old version if the image.