JavaFX WebView / WebEngine缓存外部JavaScript [英] JavaFX WebView / WebEngine Cache external JavaScript
问题描述
情况:
我有一个简单的HTML页面,其中包含这样的普通脚本标记
Situation: I have a Simple HTML page which have a normal script tag like this
<script src="main.js"></script>
我加载html后,我更新了main.js,然后重新加载(通过UI按钮) )。
After i load the html , i update the main.js , and make a reload (throught UI Button).
问题我的新JS未被采用,我必须关闭应用程序并再次打开它。
The Problem My new JS is not taken , i must close the Application and open it again.
我做了什么尝试:
-not使用webEngine.reload(),但webEngine.load()
-每次重新加载时都会制作一个新的broswer。
-制作一个新的舞台,带有一个新的broswer
-设置所有节点缓存
-in HTML代码
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" />
-InetAddressCachePolicy:
-InetAddressCachePolicy:
InetAddressCachePolicy.setNegativeIfNotSet(InetAddressCachePolicy.NEVER);
-VM选项:-Dnetworkaddress.cache.ttl = 0.
-VM Options: -Dnetworkaddress.cache.ttl=0.
问题
有没有办法删除缓存或强制WebView重新加载所有资源,而不是每次更新时都将数字附加到JS文件名?
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?
注意:我使用NetBeans 7.3使用上一个Java(更新22)
Note:I use NetBeans 7.3 With last Java (update 22)
推荐答案
我如何解决这个问题:
- 将包含HTML文件和所有JS文件的目标目录复制到随机生成的文件夹。
- on每次重新加载都会生成一个新文件夹,复制内容,删除旧文件夹,从新文件夹加载。
mcdonasm的答案是我尝试过的事情之一,如果在main.js中只有JavaScript,它会起作用,但如果它引用其他JS文件(就像我的情况一样) )其他人将被缓存。
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.
这篇关于JavaFX WebView / WebEngine缓存外部JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!