Prevent caching of external files in src iframe (using CloudFlare)

I am trying to create a playground, such as a plunker. I noticed a very strange production behavior (with active mode in Cloudflare), while it works well in localhost .

In the iframe section, the playground looks at index_internal.html , which may contain links to other files (for example, .html , .js , .css ). iframe is able to interpret external links, such as <script src="script.js"></script> .

Therefore, every time the user changes his file (for example, script.js ) in the editor, my program saves the new file to a temporary folder on the server and then updates iframe iframe.src = iframe.src , it works well on localhost .

However, I realized that in production the browser always loads the initial script.js , even if users change it in the editor, and the new version is written to a folder on the server, For example, what I see in Dev Tools ==> Network . is always the original version of script.js , whereas I can check the new version of script.js stored on the server on less on the left side.

Does anyone know why this is so? And how to fix it?

enter image description here

Change 1:

I tried the following which did not work with 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) 

I tried to add a version, it worked with index_internal.html , but did not reload script.js :

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

If I switch Cloudflare to development mode , script.js reload, but I want to keep Cloudflare in active mode .

+5
source share
1 answer

I found him.

We can create a custom rule for caching in CloudFlare:

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

For example, I can set Bypass as Cache Level for the folder www.mysite.com/tmp/* .

+2
source

All Articles