Home > Web Front-end > HTML Tutorial > HTML implements automatic cleaning of the cache of js and css files

HTML implements automatic cleaning of the cache of js and css files

王林
Release: 2020-03-02 18:04:52
forward
3624 people have browsed it

HTML implements automatic cleaning of the cache of js and css files

The method is as follows:

1. Manually clear the browser cache;

2. Add the version number (such as layout.css?v=1)

Personally, I think method 2 is faster, because clearing the browser cache requires waiting for the browser to respond. But it is troublesome to change the version number every time, so we need to find a way to automatically add the version number.

(Recommended tutorial: html tutorial)

Method 1: You can automatically add the version number to html through js

<script type="text/javascript">  
document.write("<link rel=&#39;stylesheet&#39; type=&#39;text/css&#39; href=&#39;/css/layout.css?v="+new Date().getTime()+"&#39;>");   
</script>
Copy after login

Method 2: If it is a jsp page , you can use java code to generate timestamps (if it is a jsp page, you can also use method 1, but this method is more convenient)

<link rel="stylesheet" type="text/css" href="/css/layout.css?v=<%=System.currentTimeMillis() %>">
Copy after login

For more programming-related content, please pay attention to the php Chinese websiteIntroduction to Programming Column!

The above is the detailed content of HTML implements automatic cleaning of the cache of js and css files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template