Browsing the boilerplate code at http://html5boilerplate.com/ I'm puzzled at this usage:
<link rel="stylesheet" href="css/style.css?v=1">
A querystring is a set of characters input to a computer or Web browser and sent to a query program to recover specific information from a database .
A query string is a collection of characters input to a computer or web browser. A Query String is helpful when we want to transfer a value from one page to another.
A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.
A query string is a term for adding/passing data in the URL. It is not language specific.
To force update if it is already in browser cache. the v is probably short for version.
To expand on Simon's correct answer...
Often to conserve bandwidth, stylesheets (amongst other site assets) send headers to the browser that say they should expire a long time from now (often a year). They also send the 304 not modified header.
This is great, but what if someone wants to update the stylesheet? If it was requested as style.css
, and subsequent requests were to style.css
, the end user would never redownload it (not for a year anyway).
To combat this, you can append a query string that changes when the file does. For example, it can be easily done in PHP
<?php
$file = 'style.css';
?>
<style type="text/css" rel="stylesheet" href="<?php echo $file . '?v=' . filemtime($file); ?>" />
Now, when the file is updated, the query string changes and the file is redownloaded to all end users. It will not be downloaded again until (a) the expiry time is up or (b) the query string changes again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With