Andrew-Dufresne
Andrew-Dufresne

Reputation: 5624

What do these numbers mean after png image path?

I have seen following CSS rule at two website

/* First example */
background: #F8F8F8 url('/images/noise.png?1333540701') top left;
/* Second example from a different site */
background: #F8F8F8 url('/images/noise.png?1326131369') top left; 

What does *.png?randomNumbers mean after png image path? What purpose they serve here?

First one is from bastsov and the other is from Matt Gemmell. Both use Octopress framework.

Edit It is not that both rules are being used at the same site. Each rule comes from a different site.

Moreover, it seems they use the same number everywhere, whenever noise.png is mentioned. For example,

/* rule for navigation bar */
background: url('/images/noise.png?1333540701'),linear-gradient(#E0E0E0,#CCC,#B0B0B0)
/* rule for #main */
background: #F2F2F2 url('/images/noise.png?1333540701') top left;

I observed the same pattern but with different numbers at Matt Gemmell's site.

Upvotes: 2

Views: 1620

Answers (3)

Guffa
Guffa

Reputation: 700322

The number is just a part of the URL that is sent to the server to fetch the image.

There are two common reasons for doing this:

  • The resource on the server is not a static file, it is handled by code, and it returns different images depending on the number.
  • The number is ignored by the server, and it's just used to produce different URLs. This is usually for caching reasons, so that changing the number will force a new request to the server.

In this case the second reasons seems more likely. When a query string is used to return different images, the resource name is usually more generic.

Upvotes: 3

Blender
Blender

Reputation: 298166

The random numbers are a GET request being sent to the image path. Since the image is just a static resource, nothing should change when you pass it parameters aside from its URL.

Browsers cache images to speed up page loading, but if you change the URL of the image, the browser re-downloads the image. It seems like noise.png needs to be re-loaded every time.

Upvotes: 3

Gabe
Gabe

Reputation: 50493

Most likely it's a way to version the images since they are probably caching images. That way if the image is updated, they can change the numbers to avoid getting the older, cached image.

Upvotes: 5

Related Questions