Cross-Browser Archiving

Platforms Affected

Netscape 4 prefers using compressed jars, Netscape 3 can only use uncompressed zips, IE uses cab files (or jar in the latest versions).

Details On Cross-Browser Archiving

While IE has a totally different way of reading archive files, at least it is consistent between its versions. Netscape on the other hand uses two formats. It first introduced uncompressed ZIP files in Netscape 3. In Netscape 4, Netscape was allowed to use compressed ZIPs or compressed JAR files.

This leads to the question of how do we code Netscape's ARCHIVE tag to force loading of JAR files in NS 4 and ZIP files in NS 3?

Doing some experimentation, it appears that the proper way to do this is to make sure the ZIP files appear first in the archive tag. The reason for this is that NS 3 loads the classes from the first archive in the list FIRST.

NS 4, though, loads the LAST archive in the list first. This is perfect. You can simply list the ZIPs first and the JARs last.

This behavior was tested by created multiple class files of the same name. However, the text field they print was coded different differently.

The class file with the message "NoArchiveWrapper Here For Test" is kept in the bare class file. While, a class file with the message "ZIP Wrapper Here For Test" is kept in a class file that is zipped up and moved to the main Java directory. Similar "wrapper messages" were coded for the other archive formats.

By doing this, you can tell if the applet tag is loading the class that is bare, wrapped in a zip file, wrapped in a jar file, or wrapped in a cab file since the message in the resulting text field comes out depending on which class file was really loaded.

If you want to be absolutely sure that you are not relying on behavior that may change at any time, you can use JavaScript to output a Browser specific tag. The following JavaScript code in this HTML file does that for the last Applet Demonstration.

<SCRIPT LANGUAGE="JavaScript">
<!--
  if (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) {
    document.writeln('<APPLET CODE="ArchiveTest3.class" CODEBASE="./Java" ARCHIVE="archivetest3.jar" HEIGHT=50 WIDTH=300>');
  } else {
    document.writeln('<APPLET CODE="ArchiveTest3.class" CODEBASE="./Java" ARCHIVE="archivetest3.zip" HEIGHT=50 WIDTH=300>');
  }
//-->
</SCRIPT>

References

Java Tip 21: Use archive files to speed up applet loading Gives a good overview of why you want to archive. Does not talk about how to rectify JAR versus ZIP format in Browsers.

Applet Demonstrating Jar Before Zip In ARCHIVE Tag

View The Source To ArchiveTest1.java
View The Source To Cab1/ArchiveTest1.java
View The Source To Jar1/ArchiveTest1.java
View The Source To Zip1/ArchiveTest1.java

Applet Demonstrating Zip Before Jar In ARCHIVE Tag

View The Source To ArchiveTest2.java
View The Source To Cab1/ArchiveTest2.java
View The Source To Jar1/ArchiveTest2.java
View The Source To Zip1/ArchiveTest2.java

Applet With JavaScript To Create Browser-Specific ARCHIVE Tag

View The Source To ArchiveTest3.java
View The Source To Cab1/ArchiveTest3.java
View The Source To Jar1/ArchiveTest3.java
View The Source To Zip1/ArchiveTest3.java

Gunther Birznieks <gunther@clark.net>