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

Three Discussions on Iframe Adaptive Height Code

When building a B/S system interface, you often en...

Introduction to JavaScript conditional access attributes and arrow functions

Table of contents 1. Conditional access attribute...

Detailed explanation of daily_routine example code in Linux

First look at the example code: #/bin/bash cal da...

Detailed explanation of MySQL semi-synchronization

Table of contents Preface MySQL master-slave repl...

Vue calculated property implementation transcript

This article shares the Vue calculation property ...

Native JS to implement login box email prompt

This article shares a native JS implementation of...

How to solve the problem of forgetting the root password of Mysql on Mac

I haven't used mysql on my computer for a lon...

Tips for adding favicon to a website: a small icon in front of the URL

The so-called favicon, which is the abbreviation o...

Navicat for MySql Visual Import CSV File

This article shares the specific code of Navicat ...

jQuery implements sliding tab

This article example shares the specific code of ...

How to remove the dividing line of a web page table

<br />How to remove the dividing lines of a ...

Detailed explanation of the correct use of the if function in MySQL

For what I am going to write today, the program r...