如何强制 Java Applet 加载出缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4261169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:34:25  来源:igfitidea点击:

How to force a Java Applet to Load out of Cache

javahtmlappletcache-control

提问by Uri

My friend and I are developing a little game and we want to share the development stages with our friends. So I made this little page http://people.scs.carleton.ca/~manders8/game.html

我和我的朋友正在开发一个小游戏,我们想与我们的朋友分享开发阶段。所以我做了这个小页面http://people.scs.carleton.ca/~manders8/game.html

Right now it's one .class file that we're updating. But for some reason it always loads the old version. I know there's a way to turn off java caching but my friends aren't that competent. Plus to get people to play your game it should super easy and not requiring like 5 steps with screens shots just to try it out.

现在它是我们正在更新的一个 .class 文件。但由于某种原因,它总是加载旧版本。我知道有一种方法可以关闭 Java 缓存,但我的朋友们没有那么能干。另外,为了让人们玩你的游戏,它应该非常简单,不需要像 5 个屏幕截图步骤来尝试一下。

I have this is the tag:

我有这个标签:

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">

Because I thought it might be browser related but that doesn't help.

因为我认为它可能与浏览器有关,但这无济于事。

This is my code

这是我的代码

<applet code="com.murderbody.prototype.TitleScreen.class" codebase="http://people.scs.carleton.ca/~manders8/content/" width=640 height=380></applet>

Changed from applet to:

从小程序更改为:

<object type="application/x-java-applet;version=1.5" width="640" height="380">
     <param name="codebase" value="http://people.scs.carleton.ca/~manders8/content/">
     <param name="code" value="com.murderbody.prototype.TitleScreen.class">
     <param name="cache_option" value="no">
</object>

回答by Powerlord

Add this inside your Applet tag: <param name="cache_option" value="no">

将其添加到您的 Applet 标签中: <param name="cache_option" value="no">

Speaking of Applet tags, they've been obsolete for years; consider using the objecttaginstead.

说到 Applet 标签,它们已经过时多年了。考虑改用object标签

回答by Carles Barrobés

The caching of Java applets may happen at two levels: the browser and the Java plugin. Your problem seems to be with the plugin. I just found this:

Java 小程序的缓存可能发生在两个级别:浏览器和 Java 插件。您的问题似乎与插件有关。我刚刚发现这个:

http://java.sun.com/products/plugin/1.3/docs/appletcaching.html

http://java.sun.com/products/plugin/1.3/docs/appletcaching.html

One approach some people use is resource versioning, i.e. generate a new applet filename for each version (better if you package the applet in a jar file and rename the jar for each new version, e.g. titlescreen-1.2.23.jar). If you have a decent build tool (ant, maven) that can automate this renaming for you, both at the JAR and tag level, the better.

有些人使用的一种方法是资源版本控制,即为每个版本生成一个新的小程序文件名(如果您将小程序打包在一个 jar 文件中并为每个新版本重命名该 jar,则更好,例如 titlescreen-1.2.23.jar)。如果您有一个不错的构建工具(ant、maven)可以在 JAR 和标记级别为您自动进行重命名,那就更好了。

回答by Mike Caron

Those tags will do wonders to prevent the pagefrom being cached. However, the applet is separate. :)

这些标签会产生奇迹,以防止页面被缓存。但是,小程序是独立的。:)

You need to configure the server to send those headers with the class file itself (if possible, investigate .htaccesssupport).

您需要将服务器配置为使用类文件本身发送这些标头(如果可能,请调查.htaccess支持)。

If that's not possible, but you have access to PHP or some server-side scripting language, you could use something like this:

如果这是不可能的,但您可以访问 PHP 或某些服务器端脚本语言,则可以使用以下内容:

<applet code="com.murderbody.prototype.TitleScreen.class?<?php echo rand(1, 10000);?>" codebase="http://people.scs.carleton.ca/~manders8/content/" width=640 height=380></applet>

Edit: Also, R. Bemrose has a good idea. Try adding this to the applet tag:

编辑:另外,R. Bemrose 有一个好主意。尝试将其添加到小程序标记中:

<param name="cache_option" value="no">

If that ends up being the solution, be sure to accept his answer :)

如果这最终成为解决方案,请务必接受他的回答:)