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

Sof*_*mur 5 iframe caching browser-cache html-head cloudflare

我想做一个像plunker一样的游乐场.我刚刚注意到一个非常奇怪的生产行为(使用active modeCloudflare),而它的效果很好localhost.

通过iframe,操场预览index_internal.html可能包含链接到其他文件(例如,.html,.js,.css).iframe能够解释外部链接,如<script src="script.js"></script>.

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

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

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

在此输入图像描述

编辑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)
Run Code Online (Sandbox Code Playgroud)

我试图添加一个版本,它可以使用index_internal.html,但没有重新加载script.js:

var newSrc = iframe.src.split('?')[0] 
iframe.src = newSrc + "?uid=" + Math.floor((Math.random() * 100000) + 1);
Run Code Online (Sandbox Code Playgroud)

如果我将Cloudflare转换为development mode,script.js重新加载,但我确实希望保持Cloudflare active mode.

Sof*_*mur 2

我找到了。

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

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

例如,我可以将文件夹设置Bypass为.Cache Levelwww.mysite.com/tmp/*