【问题标题】:Bootstrap3 Modal with remote html file - disabling cache带有远程 html 文件的 Bootstrap3 模态 - 禁用缓存
【发布时间】:2015-10-05 15:19:18
【问题描述】:

我正在使用 Twitter Bootstrap,在我的代码中,我显示了一个带有指向外部 HTML 文件的远程选项的模式。 HTML 文件加载正常,模式显示正常。问题是,一旦我对 html 文件进行更改并再次启动它,它不会加载更改,直到我删除浏览器缓存。

这是我的代码:

$('#modal').modal({
    remote: baseUrl + 'Content/templates/speedtest.html'
});

speedtest 包含以下内容:

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">Title</h4>
        </div>
        <div class="modal-body">
            My Message
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
    </div>
</div>

在开发过程中它非常不实用,因为我想对 html 进行更改,然后快速查看更改而无需删除缓存。

另外,我担心上传网站后如果我对html进行更改,访问者会得到无关紧要的结果。

如何禁用/配置缓存?

谢谢

【问题讨论】:

  • @FUserThrowError - 这不是同一情况。您提到的问题是关于在浏览器仍在同一页面上时打开并且只是更改远程选项。我说的是一个单一的模式,即使在浏览器关闭并重新打开后也不会给我更新的 html。
  • $.ajaxSetup({ cache: false }); 可能会有所帮助
  • @Dale - 谢谢。但是,虽然它确实有帮助,但它会导致我的网站的 ajax 部分我确实想使用缓存而不被缓存。有解决办法吗?
  • 如果您正在运行特定的 ajax 调用,您可以添加 cache: true 作为选项对象的属性,以不缓存该特定调用

标签: html twitter-bootstrap twitter-bootstrap-3 bootstrap-modal


【解决方案1】:

我有一个解决方案很简单,在末尾添加 new Date().getTime()

$('#modal').modal({
  remote: baseUrl + 'Content/templates/speedtest.html?'+new Date().getTime()
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2021-05-11
    相关资源
    最近更新 更多