Compressing Files
Gzip File
If you deploy your Nexaweb application to a server that supports gzip compressed files, you can use gzip to compress any files associated with your Nexaweb application.
Nexaweb platform includes a servlet, servlet com.nexaweb.server.servlet.CompressedFileServlet, to serve gzip files to clients from a Tomcat server. For other types of servers, you need to create your own servlet to provide gzip files to a Nexaweb application client.
servlet com.nexaweb.server.servlet.CompressedFileServlet does the following:
Checks whether the incoming client request supports gzip encoded responses.
- If not: the servlet forwards the file request directly to the web server.
- If so:
- The servlet gets the appropriate mime-type for the file being requested (the original file request).
- Checks for a .gz (gzipped) version of the file.
- If found: returns the .gz version of the file.
This response indicates the original file's mime-type and a content-encoding header specifiying gzip.For example, for the file: js.gz, you see the following:
Content-Encoding: gzip
Content-Type: application/x-javascript- If not found: forwards the file request directly to the web server.
The platform seed web.xml file maps the path to this file as: /CompressedFileServlet.
To utilize this, use:
/CompressedFileServlet/path/to/file
pack200 Compression
Requires Platform 4.2+
- pack200 compressed JAR files transfer significantly faster over a network than other JAR files
- Nexaweb compresses NexawebClient.and Nexaweb-nfc JARs using pack200
- You can now use pack200 to compress JARs containing libraries pre-loaded into your application’s client.
Using pack200 Compression
- Use pack200 compression for deploying Nexaweb applications
- Use with JAR files containing pre-loaded client libraries
- Use with unsigned JAR files
Note: For information on how to us pack200 with signed JAR files, see Sun’s Java Documentation including:
http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html#pack200_compression.
Requirements
Environment | Requirement | Description |
Building Nexaweb applications | JRE 5 (1.5) | Required in build environment to compress JARs with pack200 |
Client runtime | JRE 5 (1.5) | Installed on browser in which client runs Applet caching enabled on the browser JRE plug-in Note: Nexaweb application development requires you to include a non-compressed JAR file containing your pre-loaded libraries to ensure that these libraries load in a browser even if it does not have the JRE 5 (1.5) plug-in. |
Server runtime | n/a |
- Creating a pack200 compressed file
- Adding a pack200 attribute entry into the Nexaweb client configuration file
Creating a pack200 File
- Package pre-loaded library files in an unsigned JAR file.
Note: To use signed files, see Java documentation on how to repackage a signed JAR. - Locate the pack200 utility in JRE_HOME or JAVA_HOME bin directory.
- Copy the JAR file that you want to compress into the same bin directory as pack2000.
- Type the following command in a command window: pack200 MyLibrary.jar.pack.gz MyLibrary.jar
where:
- MyLibrary.jar.pack.gz is the name of the compressed JAR file that pack200 creates
- MyLibrary.jar is the name of the original uncompressed file - Copy both the compressed and uncompressed JARs (for example, MyLibrary.jar.pack.gz and MyLibrary.jar) into the directory where you save pre-loaded client libraries for your application. This process does not change the original MyLibrary.jar file, so if a copy of it already exists in this directory, you do not need to copy it into the directory again.
Adding a pack200 file to the nexaweb-client.xml configuration file
pack200Path="/WEB-INF/client/lib/foo.jar" pack200Url=http://blah:18/foo.jar
- Locate the nexaweb-client.xml file for the Nexaweb application in the application’s WebContent\WEB-INF directory.
- Open nexaweb-client.xml file with a text editor.
Locate the <pre-loaded-in-applet-def> section of the nexaweb-client.xml file, similar to the following:
<client-classpath> <pre-loaded-in-applet-def> <archive name="MyLibrary.jar" path="/WEB-INF/client/lib/MyLibrary.jar" /> </pre-loaded-in-applet-def> </client-classpath>
Add a pack200Path or pack200Url attribute, similar to the following:
<client-classpath> <pre-loaded-in-applet-def> <archive name=" MyLibrary.jar " path="/WEB-INF/client/lib/ MyLibrary.jar " pack200Path="/WEB-INF/client/lib/ MyLibrary.jar.pack.gz"/> </pre-loaded-in-applet-def> </client-classpath>
Troubleshooting
- Using a network monitor
- Using Nexaweb platform’s service console
Using a Network Monitor
- HTTP traffic
- Resources requested
- Resources returned
Component | Header | Header Type |
Client | accept-encoding: pack200-gzip,gzip | Request |
Nexaweb’s ClientClassService | If properly configured, returns the pack200 file data and: Content-Encoding: pack200-gzip | Response |
Nexaweb’s ClientClassService | If pack200 file is already cached on the client side: HTTP 304 | Response |
Using Nexaweb Platform's Service Console
- Library name and location mappings
- Counters
- Enter the following address in a Web browser location bar: http://server:port/yourapp/Nexaweb/Services/index.jsp
- Click right menu on ClientClassService.