url加时间戳方法及作用


速记:URL 的末尾追加了时间。这就确保了请求不会在它第一次被发送后即缓存,而是会在此方法每次被调用后重新创建和重发;此 URL 会由于时间戳的不同而稍微有些不同。这种技巧常被用于确保到脚本的 POST 每次都会实际生成新请求且 Web 服务器不会尝试缓存来自服务器的响应。

// 解决浏览器缓存的问题
function timestamp(url){
	var getTimestamp=new Date().getTime();
	if(url.indexOf("?")>-1){
		url=url+"&timestamp="+getTimestamp
	}else{
		url=url+"?timestamp="+getTimestamp
	}
	return url
}
url.indexOf("?")>-1?`${url}&timestamp=${new Date().getTime()}`:`${url}?=timestamp${new Date().getTime()}`


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM