Home >Web Front-end >JS Tutorial >js clear browser cache

js clear browser cache

不言
不言Original
2018-04-04 11:41:164323browse

The content of this article is about js clearing browser cache. I share it with everyone here. It can also be used as a reference for friends in need. Let’s take a look together


1. Meta method

        <META HTTP-EQUIV="pragma" CONTENT="no-cache"><!-- 禁止浏览器从本地计算机的缓存中访问页面内容 --> 
        <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><!-- 用于指定请求和响应遵循的缓存机制 --> 
        <META HTTP-EQUIV="expires" CONTENT="0"><!-- 用于设定网页的到期时间,一旦网页过期,必须到服务器上重新传输; -->


The approach followed by Baidu at first, but it is not suitable for 360

2. Dynamically introduce js + timestamp

去除静态html的缓存--动态引入js文件

动态引入js文件以及在js文件后边添加动态参数<script src="http://wechat.yiwang.com/appwxshare/js/share_test.js" type="text/javascript" ></script>

Code

<html><meta charset="utf-8" /><body>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script>
        window.onload=function(){

            var script=document.createElement("script");
            script.setAttribute("type", "text/javascript");            var num=Math.random();            var _url="http://wechat.yiwang.com/appwxshare/js/share_test.js?v="+num;
            script.setAttribute("src", _url);            var heads = document.getElementsByTagName("head");            if(heads.length) { 
                heads[0].appendChild(script);  
            }
        }        </script></body></html>

Related recommendations:

Understanding of object-oriented packaging objects in JS

js parses local Excel files

         

The above is the detailed content of js clear browser cache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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