iframe引入的html禁止缓存,缓存 – 防止缓存iframe的src中的外部文件(使用CloudFlare)...

我想做一个像plunker一样的游乐场.我刚刚注意到一个非常奇怪的生产行为(在Cloudflare中使用主动模式),而它在localhost中运行良好.

通过iframe,游乐场预览index_internal.html,其中可能包含指向其他文件的链接(例如,.html,.js,.css). iframe能够解释外部链接,例如< script src =“script.js”>< / script>.

因此,每当用户在编辑器上修改他们的文件(例如,script.js)时,我的程序将新文件保存到服务器上的临时文件夹中,然后通过iframe.src = iframe.src刷新iframe,它在本地主机.

但是,我意识到,在生产中,浏览器始终保持加载初始script.js,即使用户在编辑器中修改它并在服务器的文件夹中写入新版本.例如,我在Dev Tools中看到的==>网络始终是script.js的初始版本,而我可以在左侧检查保存在服务器中的新版本script.js.

有谁知道为什么会这样?以及如何解决它?

LewqU.png

编辑1:

我尝试了以下,这与script.js不兼容:

var iframe = document.getElementById('myiframe');

iframe.contentWindow.location.reload(true);

iframe.contentDocument.location.reload(true);

iframe.contentWindow.location.href = iframe.contentWindow.location.href

iframe.contentWindow.src = iframe.contentWindow.src

iframe.contentWindow.location.replace(iframe.contentWindow.location.href)

我尝试添加一个版本,它与index_internal.html一起工作,但没有重新加载script.js:

var newSrc = iframe.src.split('?')[0]

iframe.src = newSrc + "?uid=" + Math.floor((Math.random() * 100000) + 1);

如果我将Cloudflare转换为开发模式,则重新加载script.js,但我确实希望将Cloudflare保持在活动模式.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值