CSS and Javascript files play hide and seek in browsers’ cache
Fabian Piau | Sunday September 29th, 2013 - 04:09 PMYou have just updated some CSS and Javascript files on your website?
Unfortunately, your regular users will probably not see any updates because their browser will still use the old and cached versions. And you cannot control remotely the Ctrl + F5 shortcut…
To avoid this, there is a simple trick of “versioning” your files by adding a different prefix for each new version. Generally, a version number is used, for example: ?ver=x.y
.
<link rel="stylesheet" href="/css/style.css" type="text/css" media="all"/>
becomes
<link rel="stylesheet" href="/css/style.css?ver=1.1" type="text/css" media="all"/>
With this change of URL, the browser thinks it is a new file and will reload it.
Recent Comments