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

Nginx reverse proxy forwards port 80 requests to 8080

Let's first understand a wave of concepts, wh...

Several skills you must know when making web pages

1. z-index is invalid in IE6. In CSS, the z-index...

Steps to enable TLS in Docker for secure configuration

Preface I had previously enabled Docker's 237...

How to use Docker to build a development environment (Windows and Mac)

Table of contents 1. Benefits of using Docker 2. ...

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

Docker installation of MySQL (8 and 5.7)

This article will introduce how to use Docker to ...

Example analysis of mysql variable usage [system variables, user variables]

This article uses examples to illustrate the usag...

Solution for using Baidu share on Https page

Since enabling https access for the entire site, ...

Discussion on default margin and padding values ​​of common elements

Today we discussed the issue of what the margin v...

How to configure Nginx virtual host in CentOS 7.3

Experimental environment A minimally installed Ce...

Detailed explanation of docker network bidirectional connection

View Docker Network docker network ls [root@maste...

VMware virtualization kvm installation and deployment tutorial summary

Virtualization 1. Environment Centos7.3 Disable s...

Vue implements irregular screenshots

Table of contents Image capture through svg CSS p...