Improving the external performance of applets by increasing loading speed

Source: Internet
Author: User
Tags command line html tags socket zip zip archive file

Summary

This tip shows you how to create an archive file that contains all your class files so that Netscape browser users can download your applet! in the shortest time possible

One of the most common complaints about Java today is its performance. A major factor that affects the user's understanding of the speed and value of Java applets is that it takes a long time to load all the classes that make up the applet. We were willing to spend a minute or more waiting for the applet to download, and we did all this just to see some boring animations. Unfortunately, this negative impression of performance may make the applet, which is actually useful, seem useless.

To understand why this new applet loading method is faster, you need to know why the current method is so slow. An applet is usually made up of many Java. class files. For each class file, the class loader must open a separate socket connection from the browser to the server where the applet code resides. Therefore, if your applet consists of 18. class files, the browser must open at least 18 sockets to transfer each file into place. The cost of setting up and disconnecting each connection is considerable. For example, setting up each connection requires a large number of network packets to be sent back and forth, which can greatly extend the total response time (especially in today's increasingly congested network). (For specific details about the socket connection overhead, consult an important TCP/IP reference manual.) )

By now, you may have come up with a solution to this problem: put all. class files in a large file so that you can download the entire applet by simply setting up a connection. That's a good idea! This is the common idea of Netscape and Microsoft's two main Java browser camps.

Unfortunately, the two solutions they proposed are not directly compatible. Microsoft, for its own needs, created its own CAB file format. Netscape's solution is to use the existing, well-known. zip archive file format. Luckily, if you want, we can write HTML code to handle both formats. This is because each private file format is specified by a different extension of the <APPLET> HTML tag.

This article does not talk about the creation of a CAB file (because the cab will be out of business). People who are really interested in this can check Microsoft's Java developer documentation. Once you have created the CAB profile, you can use the cab by adding a cabbase HTML parameter (param) to the <APPLET> tag:

<applet name="Hello" code="HelloWorld" width="50" height="50">
<param name=codebase value="http://www.bianceng.cn/classes">
<param name=cabbase value="hello.cab">
</applet>

The value value of the Cabbase parameter is the file name of the CAB file.

It is easy to create a. zip archive file that is available for Netscape browsers. Package All. class files required by the applet into a. zip file. All you need to remember is that you just store the file in your profile (that is, no compression).

If you are using the PKZIP:

Pkzip-e0 Filearchive.zip Listofclassfiles

If you are using the Info-zip compression program:

zip-0 Filearchive.zip Listofclassfiles

Note that in both cases, the command line flag contains the number 0, not the letter O.

To use the. zip profile in an HTML file, you can specify the archive tag in the applet section:

<applet name="Hello" code="HelloWorld" width="50" height="50"
codebase="http://www.bianceng.cn/classes"
archive="hello.zip">
</applet>

Don't worry--we can go further! You can create. cab and Zip files and support both formats, which means that both Navigator and Internet Explorer users will get faster applet downloads. You don't have to worry about users who use older versions of both browsers (or any other browser) because they will still get all of the applets ' classes through the slow old way. Combine the above content:

<applet name="Hello" code="HelloWorld" width="50" height="50"
codebase="http://www.bianceng.cn/classes"
archive="hello.zip">
<param name=codebase value="http://www.bianceng.cn/classes">
<param name=cabbase value="hello.cab">
</applet>

Now that you can use. cab and zip files to solve the slow download problem, I think I should tell you that JavaSoft has a new file format defined in JDK 1.1 that you can use in this new format for all image files, Audio files and class files are packaged in a file (see the Reference Resources section). JavaSoft This format as a Java Archive (JAR). <APPLET> HTML tags have been modified to handle this JAR format with the archives parameter. I'll leave you with the work of integrating these three file formats together.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.