Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to refresh cache in HTML

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to refresh the cache in HTML, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Background

Search for keywords in the search engine. Htaccess cache, you can search for many tutorials on setting up the caching of files on your website. By setting up, you can cache css, js and other infrequently updated files on the browser side, so that every time visitors visit your website, the browser can get css, js, etc., from the browser's cache without having to read them from your server. This accelerates the opening speed of the website to a certain extent, and can save your server traffic.

problem

Now the problem is that the css and js caches set by .htaccess have an expiration time. If css and js are already cached in the visitor's browser, before these css and js caches expire, the browser will only read css and js from the cache. If you modify css and js on the server, these changes will not change in the repeat customer's browser. Unless repeat customers press Ctrl + F5 to refresh your website page or manually empty the browser's cache. There are thousands of visitors to a website, and there will be a lot of repeat visitors. You can't ask every visitor to refresh the cache after updating css, so how do you deal with this problem?

Method one

Change the css file name: in fact, solving this problem is very simple, the cache marks the cached content through the file name. After you have updated the contents of the css file on the website, just change the file name of css. As in the original html, the css call statement is as follows:

The code is as follows:

Just change the name of the css file:

The code is as follows:

Another way to change the css file name is to write the version number to the file name, such as:

The code is as follows:

After the css file is updated, you can change the version number in the file name:

The code is as follows:

Method two

Add a version number to the css file: in fact, it is a bit troublesome to change the file name of the css every time you modify the css file, so we can add a version number in the load css statement (that is, in the css link? The rest) will be fine. As in the original html, the css call statement is as follows:

The code is as follows:

Just change the version number of the css file to 2012:

The code is as follows:

It should be noted that some proxy cache servers do not cache URLs that contain "?" So method 2 may invalidate your original caching function, so you can use the first method instead.

The above is all the contents of the article "how to refresh the cache in HTML". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report