当前位置: 首页 > news >正文

解决浏览器缓存问题

1.index.html文件meta标签添加属性

<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" viewport-fit=cover  >

2.提前main.html处理逻辑再跳转到index.html页

<script>// 解决浏览器缓存function timestamp(url) {const getTimestamp = new Date().getTime()if (url.indexOf('?') > -1) {url = url + '×tamp=' + getTimestamp + '&loginType=' + loginType} else {url = url + '?timestamp=' + getTimestamp + '&loginType=' + loginType}return url}const getUrlParam = name => {const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')const value = window.location.search.substr(1).match(reg)if (value != null) {// 对参数值进行解码return decodeURIComponent(value[2])}return null}const loginType = getUrlParam('loginType')// console.log('main.html当前url链接地址:' + window.location.href)const url = './index.html'const newUrl = timestamp(url, loginType)window.open(newUrl, '_self')
</script>

3.动态加载文件

3.1 封装动态加载、移除文件方法
/*** 动态加载css文件* @param {*} url* @param {*} isCache*/
export function loadCSS(url, isCache = true) {let element = document.createElement('link')element.setAttribute('rel', 'stylesheet')element.setAttribute('type', 'text/css')if (isCache) {element.setAttribute('href', url + '?t=' + new Date().getTime())} else {element.setAttribute('href', url)}document.getElementsByTagName('head')[0].append(element)// document.head.appendChild(element)
}/*** 动态加载js文件* @param {*} src* @param {*} callback*   loadScript("",function(){*   console.log("加载成功")* })* var that = this; 在方法里面使用that*/
export function loadJS(jsUrl, callback, isCache = true) {const script = document.createElement('script')const head = document.headscript.type = 'text/JavaScript'if (isCache) {script.src = jsUrl + '?t=' + new Date().getTime()} else {script.src = jsUrl}if (script.addEventListener) {script.addEventListener('load', callback, false)}document.getElementsByTagName('head')[0].append(script)// head.appendChild(script)
}/*** 移除引用的JS/CSS文件* @param filename 文件名称* @param filetype 文件类型 js/css*/
export const removeFileJSandCSS = (filename, filetype) => {const targetElement = filetype === 'js' ? 'script' : filetype === 'css' ? 'link' : 'none'const targetAttr = filetype === 'js' ? 'src' : filetype === 'css' ? 'href' : 'none'const allSuspects = document.getElementsByTagName(targetElement)for (let i = allSuspects.length; i >= 0; i--) {if (allSuspects[i] &&allSuspects[i].getAttribute(targetAttr) != null &&allSuspects[i].getAttribute(targetAttr).indexOf(filename) != -1)allSuspects[i].parentNode.removeChild(allSuspects[i])}
}
3.2 页面引入
removeFileJSandCSS('nationality.js', 'js')
loadCSS('./jQuery/jquery-ui.min.css')
loadJS('./jQuery/jquery-ui.min.js', () => {})
http://www.lryc.cn/news/251598.html

相关文章:

  • 【数据中台】开源项目(2)-Davinci可视应用平台
  • Java实现简单飞翔小鸟游戏
  • numpy实现神经网络
  • Bean的加载控制
  • 使用 OpenCV 识别和裁剪黑白图像上的白色矩形--含源码
  • LeetCode 每日一题 Day1
  • 【hacker送书活动第7期】Python网络爬虫入门到实战
  • 【算法】希尔排序
  • 四、Zookeeper节点类型
  • arcgis导出某个属性的栅格
  • 计算机网络——传输层
  • 策略设计模式
  • Golang中rune和Byte,字符和字符串有什么不一样
  • 实施工程师运维工程师面试题
  • 6-13连接两个字符串
  • Linux中的文件IO
  • 深度学习记录--初识向量化
  • 树与二叉树堆:经典OJ题集(2)
  • Java面试题(每天10题)-------连载(40)
  • 2023年【起重机司机(限桥式起重机)】报名考试及起重机司机(限桥式起重机)考试资料
  • Linux的基本指令(3)
  • C语言memcpy,memmove的介绍及模拟实现
  • 克服.360勒索病毒:.360勒索病毒的解密和预防
  • 21、Resnet50 中包含哪些算法?
  • pybind11教程
  • Java基础- 自定义类加载器
  • 2022年高校大数据挑战赛A题工业机械设备故障预测求解全过程论文及程序
  • 洛谷 P1998 阶乘之和 C++代码
  • 洛谷 B2006 地球人口承载力估计 C++代码
  • 少走弯路:OpenCV、insightface 等多方案人脸推理和识别