xref: Static vs. Dynamic Script Versions | WebReference

xref: Static vs. Dynamic Script Versions

By Dan Ragle


[previous] [next]

xref [con't]


xref: The Static Version

The static version of xref is exactly that: A single JavaScript that you can place on your site and include in your pages with the following statement:

<script type="text/javascript" 
        src="https://example.com/xref/xref.js">
</script>

(Which of course assumes you are the Webmaster of example.com and you placed the static JavaScript in /xref/xref.js.) Those of you who don't have a Perl backend, who don't have access to install a script in your cgi-bin, have a relatively small list of targeted terms (that doesn't change often, if at all), or simply don't want or need the extended features of the dynamic version of xref will choose to use this static version. You can tailor a custom, static version of xref for use on your site here. To create the script, you'll need to know which terms you want to link to (including the URL you will link to, as well as a brief description of the term, if you wish); as well as which options you want to invoke within the script. You can then provide the details to our custom xref script builder, which will generate the script according to your needs. We'll examine each of the available options a little later in this article; but if the documentation bores you, feel free to play with the script maker now.

xref: The Dynamic Version

The dynamic version of xref also delivers a JavaScript to the end user, but instead of delivering the same static JavaScript file to each visitor (be they visiting your pages or your affiliate pages), the dynamic version leverages Perl on the backend to deliver a real-time version of the script, complete with options provided by the page the script is included on, and perhaps even including a dynamically generated list of search terms. To install the dynamic version of the script on your site, you'll need the Perl interpreter (v5.6.1 or later is required; and v5.8 or later is recommended), as well as the HTML::Template and Date::Format modules (contact your site administrator if you're unsure about these requirements). Other modules are also used, but they should be included in your Perl distribution.

Though it takes a little more initial setup on the backend, actually adding the script to Web pages is almost identical to the static version of the script. Specifically, you add one line of JavaScript to your pages:

<script type="text/javascript" 
        src="https://example.com/cgi-bin/xref.js">
</script>

Note that in this case, we've pointed to the xref.js in our cgi-bin, which, in fact, is not a JavaScript file at all! Instead, it's a Perl script that delivers a JavaScript to the browser--an architecture that provides us with key benefits not available in the static version:

  • Page-Specific Customizations: With the dynamic version, we can tweak the behavior of the JavaScript on a page-by-page basis without requiring direct adjustments to the script itself, by simply providing selected parameters with our initial JavaScript request. For example, to supply a specific link classname for use in the script, we would just do this:

    <script type="text/javascript" 
            src="https://example.com/cgi-bin/xref.js?link_class=autoLinks">
    </script>
    We'll discuss the available parameters and their meanings on the next page. Though many of these parameters are also available for use when building the static version of the script, once that script is actually generated it will always use those features; no matter where (what page) it's called from. The dynamic version of the script instead allows you to vary the parameters on each page you install the script on, if necessary (this feature is especially helpful to affiliates, who may need to tweak the script slightly to avoid conflicts with other page constructs on their sites).
  • Dynamic Selection of Terms: With the dynamic version of the script, you have the potential ability to dynamically retrieve the terms that you will target for automatic linking. Since the script is in fact a Perl script running on your Web server, you can pull the terms from any location that Perl has access to; perhaps an XML file, or even a live database. You're limited only by your knowledge of Perl!

  • Smaller Code: In most cases, the dynamic version of the script will deliver a smaller amount of JavaScript (byte-for-byte) then the static version. This is because the initial delivery of JavaScript in the dynamic version contains only the actual terms that we're looking to match; with the descriptions withheld until an actual matching term has been found. In the static version of the script, the script must contain the full list of titles with their descriptions, which dramatically increases the size of the script delivered to the browser.

The dynamic version of the script can be downloaded here. Once you have the file, unzip it in its own directory, and view the README.TXT for installation information.

We mentioned above that several parameters are available to help you control what xref does and how it does it. On the next page, we examine these parameters in detail.


[previous] [next]