This is used to prevent caching in files that have been updated, in the case for the browser (or client software that supports HTTP) it considers these urls different addresses and therefore for each will be generated a different cache:
//exemplo.com/static/css/style.css
//exemplo.com/static/css/style.css?
//exemplo.com/static/css/style.css?0000
//exemplo.com/static/css/style.css?0001
Then every file modification style.css
the suffix value is changed to prevent the browser from loading the cache file.
For example, the initial url is:
//exemplo.com/static/css/style.css?1428260681
This number in front (?1428260681
) is the Unix-time of the last modification of style.css
, when editing it a server-side language (or something equivalent) for example detects the last modification and adds a new number to the suffix, an example like PHP:
//Pega o arquivo pelo caminho real e retorna a última modificação em segundos
$utlima_modificao = filemtime('/home/user/www/project/static/style.css');
And we use it like this:
<link href="static/style.css?<?php echo $utlima_modificao; ?>">
The variable $utlima_modificao
will return a number in seconds (Unix-time) of the last modification, so if there is a change the number will be different.
This way if there is any modification in the CSS (or JS) file we can prevent users from accessing the old version that may be cached.
Note that this is a basic example technique, there are many others, for this reason not always the suffixes used will be the time in seconds of the last modification.
Reported:
If you want to know how to cache static files, read the link: It is possible to use if-modified-Since with "304 not modified" without PHP
This forces you not to cache old versions of CSS. I particularly prefer to write already in the file name if it is to do so, instead of saving with the same name.
– Bacco
hahaha. Really, Versionar is a good one, since if the site is constant and there is no change in the structure of the file all day then leave cached is better for user experience right..
– Ale