A simple way to clear the CSS, JavaScript and background image cache in the browser

A simple way to clear the CSS, JavaScript and background image cache in the browser
In the actual project development process, the page is uploaded to the server. In order to reduce the pressure on the server and let users load less, the browser will cache images, CSS, and JS locally for use the next time the website is visited. Doing so not only reduces the pressure on the server, but also reduces the number of downloads for users, providing a better user experience.

However, when upgrading the version or making some adjustments to CSS, JS, etc., the cache causes users to be unable to display the updated style, which is a headache. Unless the user manually upgrades the cache, almost all users will not manually clear the cache in order to access the website normally, because users don’t know whether it is a cache problem. In the final analysis, users just think that there is a problem with your page and it cannot be accessed normally.

In order to use the cache normally and avoid such problems, we can use our brains to think about how to solve this problem?

If the changed style cannot be accessed normally, what about changing the style file name? The answer is yes, and it will not be verified here. However, it is obviously too troublesome to manually change the file name every time. Is it possible not to change the file name? The answer is yes. We may add a version number after the imported file name, which is different from the previous version (usually the update date). The code is as follows:

Copy code
The code is as follows:

<link rel="stylesheet" type="text/css" href="reset.css?v=20140829">
<script type="text/javascript" src="core.js?v=20140829"></script>

You can see that my CSS file name and JS file name are followed by "v=20140829". This way, I can cache the files without changing the file name and update them in real time. "v=20140829" is just a common writing habit and can be changed to other ones.

Finally, there are pictures. Generally, pictures with img tags will not have duplicate names because the file names are generated in the background. If it is a picture with a fixed file name, the method is the same as above. As for the background image, since the style name is changed, the image resolution path is naturally updated synchronously, so the background image is also updated.

<<:  Summary of MySQL's commonly used database and table sharding solutions

>>:  Detailed explanation of basic concepts of HTML

Recommend

Graphic tutorial on configuring nginx file server in windows 10 system

Download the Windows version of Nginx from the Ng...

Detailed explanation of Docker container network port configuration process

Exposing network ports In fact, there are two par...

Detailed explanation of MySQL backup process using Xtrabackup

Table of contents 01 Background 02 Introduction 0...

W3C Tutorial (4): W3C XHTML Activities

HTML is a hybrid language used for publishing on ...

iview implements dynamic form and custom verification time period overlap

Dynamically adding form items iview's dynamic...

Some "pitfalls" of MySQL database upgrade

For commercial databases, database upgrade is a h...

Docker uses nextcloud to build a private Baidu cloud disk

Suddenly, I needed to build a private service for...

MYSQL master-slave replication knowledge points summary

An optimization solution when a single MYSQL serv...

MySQL transaction autocommit automatic commit operation

The default operating mode of MySQL is autocommit...

MySQL full backup and quick recovery methods

A simple MySQL full backup script that backs up t...

Real-time refresh of long connection on Vue+WebSocket page

Recently, the Vue project needs to refresh the da...

Mysql example of splitting into multiple rows and columns by specific symbols

Some fault code tables use the following design p...

Solve the error "Can't locate ExtUtils/MakeMaker.pm in @INC"

When installing mha4mysql, the steps are roughly:...

Analysis of GTK treeview principle and usage

The GtkTreeView component is an advanced componen...