我想做一个像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.
有谁知道为什么会这样?以及如何解决它?
编辑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保持在活动模式.