caching - 防止缓存 iframe src 中的外部文件(使用 CloudFlare)

标签 caching iframe browser-cache cloudflare html-head

我正在努力打造一个像 plunker 一样的游乐场。我刚刚注意到生产中的一个非常奇怪的行为(Cloudflare 中的 active mode),而它在 localhost 中运行良好。 .

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

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

然而,我意识到,在生产中,浏览器总是不断加载 初始 script.js ,即使用户在编辑器中修改它并且在服务器的文件夹中写入新版本。例如,我在 Dev Tools ==> Network 中看到的始终是 script.js 的初始版本, 而我可以查看 script.js 的新版本保存在服务器中 less在左手。

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

enter image description here

编辑 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 转到 development mode , script.js已重新加载,但我确实希望将 Cloudflare 保留在 active mode 中.

最佳答案

我找到了。

我们可以为 CloudFlare 中的缓存创建自定义规则:

https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-#cache

例如,我可以设置 BypassCache Level对于文件夹 www.mysite.com/tmp/* .

关于caching - 防止缓存 iframe src 中的外部文件(使用 CloudFlare),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43954364/

相关文章:

caching - Apollo Client v3 在给定时间段后删除缓存条目

algorithm - 算法-给定一个内存访问序列,给出缓存未命中的最小次数

javascript - 确定页面在 github 页面上已过时

javascript - 如何克隆实际的 iFrame 内容,而不仅仅是 iFrame 标签内容?

iphone - iPhone 上的 Bootstrap 模式弹出问题

javascript - 在 jQuery 后台拉入 HTML 资源

javascript - 使用 RequireJS 的 URL 缓存清除参数?

caching - 禁用 S3 缓存

caching - 服务器启动时自动启动cachecluster

css - 使绝对定位的 html 适合 iframe