您好,欢迎访问一九零五行业门户网

bootstrap怎么处理缓存问题

bootstrap处理缓存问题的方法:1、在关闭的时候清除数据;2、修改请求的url,并在请求的url上加上时间戳,语句如“function remoteurl(u){...}”。
本教程操作环境:windows7系统、bootsrap3.3.7版,dell g3电脑。
百度了一下,有很多类似的情况,解决办法基本都是如下两种:
1、在关闭的时候清除数据:
$("#mymodal").on("hidden.bs.modal", function () {$(this).removedata("bs.modal");});
2、修改请求的url,在请求的url上加上时间戳。
function remoteurl(u){u += '&t=' + math.random(1000) $.get(u, '', function(data){ $('#remotemodal .modal-body').html(data) }) $('#remotemodal').modal({show:true,backdrop:false})}
上边的两个解决办法确实有效,但在ie中,第1种方法无效,第2种方法解决起来太繁琐。
我又百度到了另一种解决办法,专门针对ie的:
[outputcache(nostore = true, duration = 0, varybyparam = "*")]//不加的话,ie缓存会捣乱
该办法是要在服务器端给每个action加上,这样的话,这需要加多少action,那位作者居然嫌弃ie太垃圾了应该退出互联网界。
好了,吐糟完了,来上我的解决办法:直接修改bootstrap.js文件
位置在大约在1068行的位置,如下代码:
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { var $this = $(this) var href = $this.attr('href') var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7 var remoteurl = !/#/.test(href) && href if (remoteurl == undefined) { remoteurl = ""; } if (remoteurl.indexof("?") > -1) { remoteurl += "&" + (new date()).valueof() } else { remoteurl += "?" + (new date()).valueof() } //var option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) //上边的是原代码,增加了remoteurl来解决ie下缓存的问题 var option = $target.data('modal') ? 'toggle' : $.extend({ remote: remoteurl }, $target.data(), $this.data()) e.preventdefault() $target .modal(option, this) .one('hide', function () { $this.is(':visible') && $this.focus() }) })
注释已经说明了解决办法,我只是增加了remoteurl,在请求的url后加上时间,这样就不用一个一个的修改,也能兼顾各个浏览器了。
推荐:《bootstrap视频教程》《css视频教程》
以上就是bootstrap怎么处理缓存问题的详细内容。
其它类似信息

推荐信息