Add? V = version number after JS or CSS to prevent browser from caching


Copy code

The code is as follows:

< span style = “font size: 14px;” > CSS and JS with parameters (such as. CSS? V = and. JS? V = or. CSS? Version = and. JS? Version =)
<script type=”text/javascript” src=”jb51.js?version=1.2.6″></script>
<link rel=’stylesheet’ href=’base.css?version=2.3.3′ type=’text/css’ />

There are two possibilities for using parameters:

First, the script does not exist, but is generated dynamically by the server, so it has a version number to show the difference. That is, the above code is equivalent to

Copy code

The code is as follows:

<script type=”text/javascript” src=”jb51.js”></script>
<link rel=’stylesheet’ href=’base.css’ type=’text/css’ />

But the browser will think that he is a version of the file!

Second, the client will cache these CSS or JS files, so every time the JS or CSS file is upgraded, the client browser will download the new JS or CSS file again after changing the version number, which is the function of brush cache. You may sometimes find that when you modify the style or JS, the refresh time is the same, that is, the client cache the CSS or JS file, so adding parameters is still good!
The second situation is the most, or both. </span>

Recommended Today

Elastic search cluster operation and maintenance of 400 + nodes

This article was first published in InfoQ Anton h ä gerstrandTranslator: Yang Zhentao Catalog: Data volume Edition Node configuration index structure performance Meltwater processes millions of Posts every day, so it needs a kind of storage and retrieval technology that can deal with this level of data. We have been a loyal user of […]