You can find the latest version of this help at http://siams.com/demo/ahp/ahphelp.htm
Last updated: 21 Jan 2000

Using AHP

Contents

 

How to pack your HTML page

The simplest way of using AlgART HTML Packer is packing large HTML pages without JavaScript. It's a simple operation. Here is a precise instruction describing how You can pack HTML page by means of AHP.

  1. Please open AHP (client-side utility ahp.htm or, in professional edition, the server-side utility ahp.asp) in Microsoft Internet Explorer 4.0+ or Netscape Navigator 4.0+.
  2. Please open your unpacked HTML page in the same Web-browser (in another window).
  3. Please start your HTML editor (for example, Microsoft FrontPage Editor) and create new empty HTML page with standard heading. For example:
                <html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
title>New Page 1</title>
<
/head>
<
body>
<
/body>
<
/html>
  1. View source HTML text of the unpacked page (View/Source in Internet Explorer, View/Page Source in Netscape). For example:
                <html>
<head>
<title>AlgART HTML Packer (AHP)</title>
</head>
<body bgcolor="#FFE7D6">
<h1 align="center"><font color="#004080"><small>New ability:</small><br>
<small>AlgART HTML Packer (AHP)</small></font></h1>
. . . . . . . . . . . . . . . . . . . . .
<li><small>address of the Web-site where You are going to use AHP.</small></li>
</ul>
</body>
</html>
  1. Copy the heading HTML text from the start <html> tag to the start <body...> tag into clipboard, switch to the HTML editor and replace the analogous part of the new empty page by the text from clipboard. In this example, the resulting page will be:
                <html>
<head>
<title>AlgART HTML Packer (AHP)</title>
</head>
<body bgcolor="#FFE7D6">
</body>
</html>

This entire HTML is not to be packed by AHP and must be identical in the packed and unpacked versions of the Web page.

  1. In the window with source HTML of the unpacked page, copy all HTML text after the start <body...> tag and until the end </body> tag into clipboard. Then switch to the AHP and paste the text into the AHP input area "Source HTML text".
  2. Check the switch "Pack HTML Page" / "Pack plain text for JavaScript" in the Packing options. It must be set to "Pack HTML Page" (default value).
  3. Press the button "Pack" in AHP.
  4. Copy all text from the AHP area Packed HTML text into clipboard. (Under Microsoft Internet Explorer 4.0+, You can click at the label "Copy to clipboard" or press Alt+C.) Then switch to the HTML editor and paste the packed HTML between <body...> and </body> tags. You will get nearly such a page:
                <html>
<head>
<title>AlgART HTML Packer (AHP)</title>
</head>
<body bgcolor="#FFE7D6">

<script language="JavaScript"><!--
function unpackLZ(s,pF,pA,pB){if(pA==null&&pB==null){pA=0;......
function __T(){return (new Date()).getTime();}
function __p(v){var t=__T();if(t-__t>500)......
var t1=__T(),t2,__n=0,__t=0,s,
sp="LZ 3s ,c 0. ! ]<h1 align=\"center\"><font color=\"#004080\">......"
+"ink: u <li><a tt=\"_blank\" href=\"e/1/jss34.htm\"a> (89Klipya (......"
+"(U*%V%T(U%)'S+%T%R%S( f T%RFV'S%S%%W()+%S*'R%......"
+"2J*s3i---V44-*7H$$8S$c +%T710/(8:r!^%#-/23(2 J(l+a.A!2+/6I$......";
__n=sp.length;window.status="Unpacking...";
s=unpackLZ(sp,__p,0,100);
t2=__T();
window.status=window.__us=s.length+" bytes unpacked over "+......
document.writeln(s);
setTimeout("window.status=window.__us",1000);
//--><
/script>
<
noscript>
<
p>JavaScript required to view this page!</p>
<
/noscript>
</body>
</html>
  1. The user can disable JavaScript in the Web-browser  (for example, in order to ensure the maximal security level for the client computer). Moreover, some old browsers don't support JavaScript. If You want your page to be viewable in these situations, please replace the text "<p>JavaScript required to view this page!</p>" (in <noscript> section) to
                <p>Click <a href="xxxx">here</a> to view the page</p>

where "xxxx" is the URL (absolute or relative) of the original unpacked page. Then, insert between <head> and <title> tags the following HTML:

                <noscript>
<
meta http-equiv="REFRESH" content="0;url=xxxx">
<
/noscript>

This HTML forces the Web-browser to navigate to the unpacked page "xxxx"automatically if JavaScript is disabled.

  1. Save the resulting  packed page.
  2. Check the results at your Web-server. If You performed the step 9, some Web-servers, in principle, can send to the browser a directive to navigate to the unpacked page, even if JavaScript is enabled in the browser. I think, this situation is very unlikely. If your browser navigates to the unpacked page when JavaScript is enabled, please remove the section <noscript><meta...></noscript>.

 

How to pack the JavaScript code

The JavaScript programmers can use AlgART HTML Packer to pack any text data, in particular a large JavaScript code. More precisely, AHP builds the JavaScript fragment, which:

If You pack some JavaScript code, You will get this code as a value of the JavaScript string variable s. Then You can execute this code by the call "eval(s)". It is a good method for including large set of JavaScript functions (16-128 Kb or larger) into HTML page.

Here is an instruction describing how You can pack JavaScript code by means of AHP.

  1. Please open AHP (client-side utility ahp.htm or, in professional edition, the server-side utility ahp.asp) in Microsoft Internet Explorer 4.0+ or Netscape Navigator 4.0+.
  2. Set the switch "Pack HTML Page" / "Pack plain text for JavaScript" (in the Packing options) to the value "Pack plain text for JavaScript".
  3. Copy your JavaScript code into the AHP input area "Source HTML text". This code can contain functions, variable declarations, any operators.
  4. Press the button "Pack".
  5. Copy all text from the AHP area Packed HTML text into clipboard. (Under Microsoft Internet Explorer 4.0+, You can click at the label "Copy to clipboard" or press Alt+C.) Then switch to your HTML editor and paste the packed text. You will get nearly such a result:
                . . . . . . . . . . . . . . . . . . . . .
<script language="JavaScript"><!--
function unpackLZ(s,pF,pA,pB){if(pA==null&&pB==null){pA=0;......
function __T(){return (new Date()).getTime();}
function __p(v){var t=__T();if(t-__t>500)......
var t1= __T(),t2,__n=0,__t=0,s,
sp="LZ /x 5! 68 #@R/* Some large JavaScript */\r\n\r\nfunction ms......"
+"222222222222222222222222222222222222233333333333333333333......"

+"8R0R8R0R8R0R8R0R8R0R8R0R8R0R8R0R8R0R8R0R8R0R8R0R8......"
+"8R0R8R0R8R0R8R0R8R%'Y!V'!V4T'w!Y1+X$SD ^ C C H d 5 n a ......"

+"TZTST]TUT_TWTaTYTcT[TeT]TeT]TeT]TeT]TeT]TeT]TeT]T......";
__n=sp.length;window.status="Unpacking...";
s= unpackLZ(sp,__p,0,100);
t2= __T();
window.status= window.__us=s.length+" bytes unpacked over "+......
setTimeout("window.status=window.__us",1000);
/***
*** (Please remove this comment from the resulting HTML page)
***
*** Now the JavaScript variable "s" contains the source text which has been packed by AHP!
*** If this text is a JavaScript code, You can add here the call
*** eval(s);
***/
//--><
/script>
<
noscript>
<
p>JavaScript required to view this page!</p>
<
/noscript>
  1. Remove the comment /***...***/ and add "eval(s)" at the end of this script section.

The call "eval(s)" will work so as if You put the source unpacked JavaScript code instead it.

You can place the resulting packed JavaScript text not only in an HTML page, but also in a JS-file - the JavaScript file which is attached by the tag <script language="JavaScript" src="xxxx.js"></script>. In this case, please copy only the content of the <script...> tag into the JS-file.

 

AHP packing options

Packing algorithms

You can choose Lempel-Ziv (LZ), Huffman or both packing algorithms.

Usually it's best to use only LZ algorithm: it gives the maximal unpacking speed and enough good compression ratio. It is the default setting.

You can increase the compression ratio by choosing both LZ and Huffman algorithms. It can be recommended if You pack large HTML document (50-100K or more), or if You design Web pages for very slow Internet connection. When packing small HTML pages, choosing both LZ and Huffman algorithms can reduce the compression ratio, because of the added JavaScript code of Huffman unpacking algorithm.

The case "Use only Huffman algorithm" can be useful in special cases when You need to pack the text, mainly, consisting of a very small set of characters (for example, only digits).

6.5 / 7.5 bits per character

The mode "7.5 bits/character" gives better compression ratio than "6.5 bits/character". However, there is some risk that the packed page will be not viewable in some browsers with some character sets. Therefore, You have to test the result of packing at the target Web-server and all popular browsers. If it doesn't work, please try to select character set of your Web-document:

                <head>
<
meta http-equiv="Content-Type" content="text/html; charset=XXXX">
. . . . . . . . . . . . . . . . . . . . .
<
/head>

The following character sets work good under Windows platform: ISO-8859-1 (Western), Windows-1250 (Central European), Windows-1251 (Cyrillic), KOI8-R (Cyrillic), ISO-8859-5 (Cyrillic), Windows-1257 (Baltic), Windows-1253 (Greek), ISO-8859-7 (Greek), ISO-8859-9 (Turkish).

The mode "6.5 bits/character" is safe, but gives the worse compression ratio.

Add self-extraction functions

AHP always returns some JavaScript code as a result of packing. This JavaScript consists of 3 parts:

  1. several JavaScript unpacking functions which perform unpacking of the packed data;
  2. the packed text as a large JavaScript string variable;
  3. small code which unpacks the packed text by means of the unpacking functions.

If You use AHP for packing many Web-pages, there are no reasons to include the unpacking functions into all pages. Instead, You can create the JavaScript include-file unpack.js, which contains these functions, and attach it to all packed pages:

                <head>
. . . . . . . . . . . . . . . . . . . . .
<
script language="JavaScript" src="xxxx/unpack.js"></script>
        <!-- here xxxx is the path to the file unpack.js in your Web-site -->
<
/head>

Then You can instruct AHP that it isn't needed to include unpacking functions in the result of packing. To do it, please clear the flag "Add self-extraction functions" in AHP settings.

How to create the file unpack.js? Please:

  1. perform the packing of some text when the flag "Add self-extraction functions" is set;
  2. see the AHP area Packed HTML text and find there the line "<script language="JavaScript"><!--" and the line which starts by "var t1= __T(),t2,__,......";
  3. select all lines between these 2 lines, not including these 2 lines;
  4. create an empty file unpack.js in some folder xxxx of your Web-site;
  5. copy there the selected lines from the AHP area Packed HTML text.

Attention! The set of required unpacking functions depends on some AHP settings: "Packing algorithms", "6.5 / 7.5 bits per character", "Compatible with Netscape 3.0". So, if You pack different pages with different settings, You must include the maximal set of unpacking functions in the JavaScript include-file unpack.js. To obtain the maximal set of unpacking functions, You must perform the packing (the step 1) with following packing options:

        Packing algorithm:
6.5 / 7.5 bits per character:

Compatible with Netscape 3.0:
    Use LZ and Huffman algorithms
7.5 bits per character
the flag is set.

You also can clear the flag "Add self-extraction functions" in the following situation. Let's suppose that You place several packed HTML or JavaScript blocks into the same target page. Let's also suppose that all these blocks are packed with the same AHP settings. Then You can clear this flag when packing all HTML/JavaScript blocks except the first block, because the unpacking functions defined in the first block will be available for all other blocks.

Pack HTML page / Pack plain text for JavaScript

The mode "Pack HTML page" provides the simplest way to pack HTML page. AHP builds a packed HTML fragment which is equivalent to the source HTML text.

The mode "Pack plain text for JavaScript" allows You to pack any text. AHP will build the JavaScript fragment which unpacks the packed data and assigns the unpacked text to the JavaScript variable s. For example, You can use this mode to pack your JavaScript code: in this case, You must call "eval(s)" after unpacking. See above the part "How to Pack the JavaScript Code".

In the mode "Pack HTML page", AHP checks the correctness of the source unpacked text: it must be an HTML content of the <body...> tag, or a part of this content. In the mode "Pack plain text for JavaScript", AHP doesn't check the text.

Remove HTML comments

If this flag is set, then HTML comments <!--...--> will be automatically removed from the text before packing. We recommend using this ability always: some browsers can have problems while unpacking HTML containing comments.

HTML comments are not removed from <script>...</script> and <style>...</style> blocks, where the comment tags <!-- and --> are placed for compatibility with old browsers and are needless in modern ones. Instead, the comment tags <!-- and --> are removed from these blocks.

Compatible with Netscape 3.0

Netscape Navigator 3.0 sometimes generates JavaScript errors for HTML pages packed by AHP, if the unpacked HTML text contains some non-latin characters or if You use the mode "7.5 bits/character". Please set the flag "compatible with Netscape 3.0" to avoid this problem. This flag is never needed if You use the mode "6.5 bits/character" and your source HTML contains only standard latin characters, digits and symbols !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.

The flag "compatible with Netscape 3.0" increases the size of the packed text by 1K.

Block identifier

(It is used only if the flag "compatible with Netscape 3.0" is set.)

You can insert more than 1 packed block into the packed page between <body...> and </body> tags. It can be useful, for example, for packing HTML which contains >30000 characters, when You run AHP under Netscape Navigator - see "Restrictions", 1.

If You insert several packed blocks into one HTML-page, and the flag "compatible with Netscape 3.0" is set, then You are to set unique block identifier for each block. Otherwise, the page will not be unpacked.

 

Restrictions

  1. Under many browsers, including Netscape 4.X, You cannot insert >30000 characters into AHP input area "Source HTML text". If You need to pack large HTML document, You may split it to several blocks and pack them separately. In this case, if the flag "compatible with Netscape 3.0" is set, You must set unique "Block identifier" (in AHP options) for packing each block.
    Microsoft Internet Explorer 4.0+ has no restrictions for the length of the text placed into an input area. We recommend to use this browser with AHP.
  2. AHP cannot pack UTF (Multilingual), Japanese, Chinese, Korean characters.
  3. AHP cannot pack style definitions in the tag <style>...</style>, except the case when You are sure that the packed page will be viewed only under Microsoft Internet Explorer 4.0+ or Netscape Navigator 4.0+. We recommend to place this tag in the unpacked part of the result page - for example, in the <head> section.