Rany A. Ishak Rany A. Ishak - 9 months ago 230
Java Question

JavaFX WebView / WebEngine Cache external JavaScript

I have a Simple HTML page which have a normal script tag like this

<script src="main.js"></script>

After i load the html , i update the main.js , and make a reload (throught UI Button).

The Problem My new JS is not taken , i must close the Application and open it again.

What i did try:
-not using webEngine.reload() , but webEngine.load()
-making a new broswer every time a reload occurs.
-making a new stage with a new broswer
-setting all nodes caching off
-in HTML following code

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />



-VM Options: -Dnetworkaddress.cache.ttl=0.

The Question
Is there any way to delete the cache or enforce the WebView to reload all resources other than appending a number to JS filename every time i update it?

Note:I use NetBeans 7.3 With last Java (update 22)

Answer Source

How i worked around that:

  • Copy target directory containing HTML file and all JS files to a random generated Folder.
  • on Each reload generate a new folder , copy the contents , delete the old folder , load from the new folder.

The answer from "mcdonasm" was one of the things i tried , it would work if in "main.js" is only JavaScript , but if it referencing other JS files (as my case) the others will be cached.